How to keep comma separator after using tostring() function?

Hello Community,

I’m concatenating two integers, but first have convert them to strings so it will concat correctly. Once I do this, I lost the comma separator. I’m sure I could use a combination of split() and left() to insert a comma, but I was wondering if the community already has a solution.

Fields:
A (integer): 11
B (integer): 3,137

Current Calculated Field: concat( toString(A) ,' | ', toString(B) )
Current Output: 11 | 3137

Desired Output: 11 | 3,137

I would like to add the comma thousands separator. Do you have a calculated field that does this? Any tips or workarounds?

Thanks, Mike

1 Like

Hello @Kashgar, unfortunately, you may have to utilize some work-around calculations for this. You can use strlen to check the length of the value, then if it is greater than 3 (may need to check for greater than 6 as well depending on the values you are expecting), you can use substring to split it into 2 string fields to add the comma.

ifelse(strlen(toString(B)) > 3, concat(substring(toString(B), 1, strlen(toString(B)) - 3), ',', substring(toString(B), round(strlen(toString(B))/2), strlen(toString(B)) - round(strlen(toString(B))/2)),
toString(B))

I may have overcomplicated this slightly but this should work up to 6 digit integers. The only thing I am not 100% certain on is the function I wrote to determine the start and length of the 2nd substring, but it seems to work out in my head. Let me know if this works for you!

1 Like

Once again, @DylanM for the win! Thank you!

1 Like