I was looking for a pre-built number formatting function and came across this JS function toLocaleString()
. This function does exactly what I want it to do.
For example, I have a number which I want to be formatted, let's say 1234567890.123
. I want this number to be formatted into 1,23,45,67,890.123
& 1,234,567,890.123
.
With the JS function I did it like this and got the desired output
var number = 1234567890.123;
number.toLocaleString('hi-IN'); //1,23,45,67,890.123
number.toLocaleString('en'); //1,234,567,890.123
However, I wanted to know if there is a built in method to do this with PHP.
NOTE: money_format() is not what I'm looking for and I just want to know if there exists such a function in PHP too. If not, no problem, I'll have to write a custom function.