Skip to content
Advertisement

Tag: string-formatting

Add commas or spaces to group every three digits

I have a function to add commas to numbers: Unfortunately, it doesn’t like decimals very well. Given the following usage examples, what is the best way to extend my function? Presumably the easiest way is to first split on the decimal point (if there is one). Where best to go from there? Answer Just split into two parts with ‘.’

Advertisement