# Number format pattern / format string

**URL:** <https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375>\
**Category:** Ignition\
**Created:** [June 30, 2021, 5:24pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375 "2021-06-30T17:24:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thiamweekhoo](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thiamweekhoo](https://forum.inductiveautomation.com/u/thiamweekhoo)\
**Post date:** [June 30, 2021, 5:24pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/1 "2021-06-30T17:24:07Z")

</div>

Hello,

Good day. May I know how can I change the format pattern of my tag ?  
My tag type is double but due to certain reason, I am using a table with string column type to display the data. I am using cell update binding for my table.

My objective is just to show **2.35** and **197.64.**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/6/c6a8e16945d3aac6352b12018a52780946f23161.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 30, 2021, 5:35pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/2 "2021-06-30T17:35:52Z")

</div>

Whatever your reasons, you’ll need to do the formatting at the point where you are converting to string.

---

<div class="post-metadata">

**Author:** ![thiamweekhoo](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thiamweekhoo](https://forum.inductiveautomation.com/u/thiamweekhoo)\
**Post date:** [June 30, 2021, 5:45pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/3 "2021-06-30T17:45:59Z")

</div>

Is this only way to do it ? I try changing the format string on the tag and it doesn’t work.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/b/bb8d8b8c7fa216f966168ad85ba6ea7128adb97a.png)

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [June 30, 2021, 5:47pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/4 "2021-06-30T17:47:25Z")

</div>

Do the formatting on table, not in tag.

---

<div class="post-metadata">

**Author:** ![thiamweekhoo](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thiamweekhoo](https://forum.inductiveautomation.com/u/thiamweekhoo)\
**Post date:** [June 30, 2021, 6:02pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/5 "2021-06-30T18:02:34Z")

</div>

how do I do that ?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 30, 2021, 6:22pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/6 "2021-06-30T18:22:11Z")

</div>

How is the tag being brought into the table? Is it part of a SELECT query? Are you creating the table data with a script? However you are generating the data for the table - that is your opportunity to format the string as you need it.

---

<div class="post-metadata">

**Author:** ![thiamweekhoo](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thiamweekhoo](https://forum.inductiveautomation.com/u/thiamweekhoo)\
**Post date:** [June 30, 2021, 6:40pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/7 "2021-06-30T18:40:58Z")

</div>

In fact, the table is in the template.  
The reason i set the column to be string due to I have string data on the same column.  
I am using Cell Update binding for the table. Each specific cell is bind to the the template custom properties. I then bind the table custom properties to the indirect tag.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/6/86be608dca3eb00f3153f7b0546eebee94f4c2de.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 30, 2021, 8:36pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/8 "2021-06-30T20:36:11Z")

</div>

Consider using a custom property on the table to hold the raw data (your cell bindings would also be in there), then process the raw dataset to the format you want and write it to the data property.

One way would be to use a try/except block to test for a float.

```python
# Create a sample dataset
sampleHeaders = ['Col1', 'Col2', 'Col3']
sampleData = [['abc', '12.3456', 'def'],
              ['789.012', 'ghi', '34.5678'],
              ['jkl', '987.54321', 'mno']
             ]

sampleds = system.dataset.toDataSet(sampleHeaders, sampleData)

#----------------------------------------------#

# Get column names and number of rows and columns
headers = list(sampleds.getColumnNames())
nRows = sampleds.getRowCount()
nCols = sampleds.getColumnCount()

# Process the dataset
data = []
for i in range(nRows):
	# Start with a blank row
	newRow = []
	for j in range(nCols):
		value = sampleds.getValueAt(i,j)
		# Try to make value a float.
		# If we can, append a formatted string.
		try:
			newRow.append('{:.2f}'.format(float(value)))
		# Otherwise, just append the original string.
		except:
			newRow.append(value)
	# Append the row to the data
	data.append(newRow)

# Create the new dataset
dataOut = system.dataset.toDataSet(headers, data)

```

```auto
raw dataset
row | Col1 | Col2 | Col3   
-----------------------------------
0 | abc | 12.3456 | def    
1 | 789.012 | ghi | 34.5678
2 | jkl | 987.54321 | mno    

updated dataset
row | Col1 | Col2 | Col3 
-----------------------------
0 | abc | 12.35 | def  
1 | 789.01 | ghi | 34.57
2 | jkl | 987.54 | mno  

```

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [July 1, 2021, 4:42pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/9 "2021-07-01T16:42:32Z")

</div>

I see this is Vision.  
In your Table or Power Table component you should add some script.

**Examples**  
Here is my demo dataset where I’ll work with “Col 3”:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/5/657885dc4818744079f4cb8d057a60024cd4d9cc.png)

**If you are using a Table:**  
Find _getDisplayTextAt_ Extension Function and add the script:

```auto
if col == 2: #Col3
	try:
		return "%.2f" % round(float(value),2)
	except:
		return value
else:
	return defaultText

```

Here is the result:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/2/f23aa3a8ba9f996d283faf01a1dbd4f266af2dff.png)

**If you are using a Power Table:**  
Find _configureCell_ Extension Function and add the script:

```auto
if colIndex == 2:
	try:
		return {'text': "%.2f" % round(float(value),2)}
	except:
		return {'text': value}

```

Here is the result:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/c/8c01d5e7c8cfb59167e183a18f4a98deb7f21aa7.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 1, 2021, 5:45pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/10 "2021-07-01T17:45:16Z")

</div>

Hmm… sounds rather familiar. 😉

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [July 1, 2021, 5:59pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/11 "2021-07-01T17:59:29Z")

</div>

Totally,  
I work with display options on tables,  
You rebuild the dataset for tables,  
How we transform data → the same!

---

<div class="post-metadata">

**Author:** ![thiamweekhoo](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thiamweekhoo](https://forum.inductiveautomation.com/u/thiamweekhoo)\
**Post date:** [July 2, 2021, 5:57pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/12 "2021-07-02T17:57:24Z")

</div>

Thanks **jespinmartin**. great solution as it saved me lots of hassle.  
Thanks to **JordanCClark** too

---

<div class="post-metadata">

**Author:** ![thiamweekhoo](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thiamweekhoo](https://forum.inductiveautomation.com/u/thiamweekhoo)\
**Post date:** [July 6, 2021, 5:40am UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/13 "2021-07-06T05:40:01Z")

</div>

How about converting it to whole number ? instead of 12.60, would like to convert to 12 instead.  
Do you mind to share where can I refer to ?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 6, 2021, 10:27am UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/14 "2021-07-06T10:27:03Z")

</div>

If you’re looking to truncate it to 12:  
`"%0d" % float(value)`

If you’re looking to round it to 13:  
`"%0d" % round(float(value))`

---

<div class="post-metadata">

**Author:** ![thiamweekhoo](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thiamweekhoo](https://forum.inductiveautomation.com/u/thiamweekhoo)\
**Post date:** [July 6, 2021, 3:47pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/15 "2021-07-06T15:47:32Z")

</div>

thanks **JordanCClark**

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 10, 2021, 12:06am UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/16 "2021-07-10T00:06:23Z")

</div>

Fwiw, all of this stuff is just Python which a quick google will invariably get you what you need to know

---

<div class="post-metadata">

**Author:** ![thiamweekhoo](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thiamweekhoo](https://forum.inductiveautomation.com/u/thiamweekhoo)\
**Post date:** [December 1, 2021, 12:26pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/17 "2021-12-01T12:26:58Z")

</div>

hi, can I ask, how to BOLD selected row and column on the table? no condition require, i.e. row 1 col 2 and row 2 col 4 text to be in BOLD.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [December 1, 2021, 3:16pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/18 "2021-12-01T15:16:55Z")

</div>

Power Table

```auto
if colIndex == 2:
	try:
		config = {'text': "%.2f" % round(float(value),2)}
		if selected:
			config['font'] = self.font.deriveFont(1)
		return config
	except:
		config = {'text': value}
		if selected:
			config['font'] = self.font.deriveFont(1)
		return config
else:
	if selected:
		return {'font':self.font.deriveFont(1)}

```

---

<div class="post-metadata">

**Author:** ![thiamweekhoo](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thiamweekhoo](https://forum.inductiveautomation.com/u/thiamweekhoo)\
**Post date:** [December 1, 2021, 3:36pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/19 "2021-12-01T15:36:33Z")

</div>

thanks sir, sorry I did not mention I was using **Table** , not power Table…

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 1, 2021, 3:54pm UTC](https://forum.inductiveautomation.com/t/number-format-pattern-format-string/48375/20 "2021-12-01T15:54:22Z")

</div>

> [@thiamweekhoo](#):
>
> I was using **Table** , not power Table…

Then you can't. Use a Power Table, instead.
