# How to maintain thousand separators when converting number to text?

**URL:** <https://community.fibery.io/t/how-to-maintain-thousand-separators-when-converting-number-to-text/7976>\
**Category:** Get Help\
**Created:** [December 17, 2024, 5:07am UTC](https://community.fibery.io/t/how-to-maintain-thousand-separators-when-converting-number-to-text/7976 "2024-12-17T05:07:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![interr0bangr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/interr0bangr/32/8089_2.png) [@interr0bangr](https://community.fibery.io/u/interr0bangr)\
**Post date:** [December 17, 2024, 5:07am UTC](https://community.fibery.io/t/how-to-maintain-thousand-separators-when-converting-number-to-text/7976/1 "2024-12-17T05:07:50Z")

</div>

If there’s a value of 123456 in a field and I turn on the thousands separator, it gets displayed as 123,456, which is great. However, when that field is converted to text with the ToText() function, the commas are ignored and it gets converted back to 123456.

Is there a way to maintain or recreate the thousand separator commas when a number is converted to text without the worlds ugliest collection of redundant if statements, length, right() & replace() functions?

I have it working (up to 999 million) but it’s pretty inefficient.

```auto
If(
  Length(
    Left(
      ToText(Round([Number Value], 2)),
      Find(ToText(Round([Number Value], 2)), ".") - 1
    )
  ) >= 7,
  Replace(
    Replace(
      If(
        Length(
          Middle(
            ToText(Round([Number Value], 2)),
            Find(ToText(Round([Number Value], 2)), ".") + 1,
            2
          )
        ) <= 1,
        ToText(Round([Number Value], 2)) + "0",
        ToText(Round([Number Value], 2))
      ),
      Middle(
        Left(
          ToText(Round([Number Value], 2)),
          Find(ToText(Round([Number Value], 2)), ".") - 1
        ),
        Find(
          Left(
            ToText(Round([Number Value], 2)),
            Find(ToText(Round([Number Value], 2)), ".") - 1
          ),
          Right(
            Left(
              ToText(Round([Number Value], 2)),
              Find(ToText(Round([Number Value], 2)), ".") - 1
            ),
            3
          )
        ) - 3,
        3
      ),
      "," +
        Middle(
          Left(
            ToText(Round([Number Value], 2)),
            Find(ToText(Round([Number Value], 2)), ".") - 1
          ),
          Find(
            Left(
              ToText(Round([Number Value], 2)),
              Find(ToText(Round([Number Value], 2)), ".") - 1
            ),
            Right(
              Left(
                ToText(Round([Number Value], 2)),
                Find(ToText(Round([Number Value], 2)), ".") - 1
              ),
              3
            )
          ) - 3,
          3
        )
    ),
    Right(
      Left(
        ToText(Round([Number Value], 2)),
        Find(ToText(Round([Number Value], 2)), ".") - 1
      ),
      3
    ),
    "," +
      Right(
        Left(
          ToText(Round([Number Value], 2)),
          Find(ToText(Round([Number Value], 2)), ".") - 1
        ),
        3
      )
  ),
  If(
    Length(
      Left(
        ToText(Round([Number Value], 2)),
        Find(ToText(Round([Number Value], 2)), ".") - 1
      )
    ) > 3,
    Replace(
      If(
        Length(
          Middle(
            ToText(Round([Number Value], 2)),
            Find(ToText(Round([Number Value], 2)), ".") + 1,
            2
          )
        ) <= 1,
        ToText(Round([Number Value], 2)) + "0",
        ToText(Round([Number Value], 2))
      ),
      Right(
        Left(
          ToText(Round([Number Value], 2)),
          Find(ToText(Round([Number Value], 2)), ".") - 1
        ),
        3
      ),
      "," +
        Right(
          Left(
            ToText(Round([Number Value], 2)),
            Find(ToText(Round([Number Value], 2)), ".") - 1
          ),
          3
        )
    ),
    If(
      Length(
        Middle(
          ToText(Round([Number Value], 2)),
          Find(ToText(Round([Number Value], 2)), ".") + 1,
          2
        )
      ) <= 1,
      ToText(Round([Number Value], 2)) + "0",
      ToText(Round([Number Value], 2))
    )
  )
)

```

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [December 17, 2024, 7:16am UTC](https://community.fibery.io/t/how-to-maintain-thousand-separators-when-converting-number-to-text/7976/2 "2024-12-17T07:16:39Z")

</div>

I would suggest using regex

> **[Regular Expressions Cookbook, 2nd Edition](https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch06s12.html)**
>
> 6.12. Add Thousand Separators to Numbers Problem You want to add commas as the thousand separator to numbers with four or more digits. You want to do this both for … - Selection from Regular Expressions Cookbook, 2nd Edition \[Book\]

---

<div class="post-metadata">

**Author:** ![drew](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/drew/32/10581_2.png) [@drew](https://community.fibery.io/u/drew)\
**Post date:** [January 21, 2025, 9:09pm UTC](https://community.fibery.io/t/how-to-maintain-thousand-separators-when-converting-number-to-text/7976/3 "2025-01-21T21:09:38Z")

</div>

@interr0bangr I found your post trying to do the same thing. And per Chris’s suggestion, I got it working:

> ReplaceRegex(ToText([Source Field]),“(?\<=\d)(?=(\d{3})+(?!\d))”,“,”)

BUT it didn’t handle long floating numbers (inserting commas _after_ the decimal too), so I refactored to only keep 2 decimal places:

> ReplaceRegex(ReplaceRegex(ToText([Source Field]), “(.\d{2})\d\*”, “\1”),“(?\<=\d)(?=(\d{3})+(?!\d))”,“,”)

Hope that helps. \*Now if you figure out how to right-align these text results in tables or cards to _look_ like numbers, please let me know. 😅
