# Format number through scripting

**URL:** <https://forum.inductiveautomation.com/t/format-number-through-scripting/92541>\
**Category:** Ignition\
**Created:** [June 28, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/format-number-through-scripting/92541 "2024-06-28T17:46:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbb5310](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jbb5310](https://forum.inductiveautomation.com/u/jbb5310)\
**Post date:** [June 28, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/format-number-through-scripting/92541/1 "2024-06-28T17:46:21Z")

</div>

I get a formatted output of #000.0 from sepasoft method and want to format my number to match this format.  
The formatted output differs from test to test which is why I make this call. Is there a way to force this format in scripting using this outputted format?

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [June 28, 2024, 5:52pm UTC](https://forum.inductiveautomation.com/t/format-number-through-scripting/92541/2 "2024-06-28T17:52:26Z")

</div>

I'm trying to understand what you're saying, but formatting essentially is "converting" a floating point value over to a string using a specified format. Is this your intent? Typically you'd only want to do this at the client display/UI level and not for passing values out of a script.

If you are wanting to pass this out of a script, use something like the following for 1 decimal place:

```python
return "%.1f" % value

```

If you want to force a minimum fixed set of characters, you can use this for a minimum of 5 characters (3 to the left of the decimal, the decimal itself, and 1 after the decimal):

```python
return "%5.1f" % value

```

If you want them zero prefixed, you'd use this:

```python
return "%05.1f" % value

```

---

<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 28, 2024, 6:03pm UTC](https://forum.inductiveautomation.com/t/format-number-through-scripting/92541/3 "2024-06-28T18:03:42Z")

</div>

Perhaps you can get Nick to share his code from this topic:

> [@Add identical "numberFormat" function in Scripting as in Expressions](https://forum.inductiveautomation.com/t/add-identical-numberformat-function-in-scripting-as-in-expressions/92377):
>
> I know that I can use Python's formatting to format numbers, but when you're trying to apply a "formatString" in script, it's not simple as you basically have to redevelop the logic inside the numberFormat expression function in script. It'd be nice if there was an identical function available to use out of the box

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [June 28, 2024, 7:28pm UTC](https://forum.inductiveautomation.com/t/format-number-through-scripting/92541/4 "2024-06-28T19:28:46Z")

</div>

If I remember correctly, the Sepasoft SPC module, for example, stores values as a string in the database (since value could be many different things). When you return the result, it returns as a string type. You can confirm this by using type() and see it comes back as a string or float. Either way, you'll need to explicitly convert that string to a float, then apply the formatting you want so they all "look" the same.
