2

I am trying to format my number in the following way

12,34,56,789.00

i tried

number_format($row{'money'},2,".",",")

I am getting

123,456,789.00 

This is not what i wanted. So, How to do this?? (12,34,56,789.00)

2
  • 4
    The number_format() method formats a number within defined/standard groups (i.e. thousands, millions, etc). Your requested format, 2 numbers + comma + 2 numbers + comma, is not a standard format. You'll have to write your own function to do that grouping (possibly with money_format()). Commented Oct 11, 2013 at 14:16
  • 1
    You can’t do that with number_format, because the functions purpose is explicitly “format a number with grouped thousands”. Commented Oct 11, 2013 at 14:18

1 Answer 1

4

You can do this just by using the PHP function called money_format

$amount = '123456789.00';
setlocale(LC_MONETARY, 'en_IN');
$amount = money_format('%!i', $amount);
echo $amount; // 12,34,56,789.00

The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.

So you can use this php code:

setlocale(LC_ALL, ''); // Locale will be different on each system.
$amount = 123456789.00;
$locale = localeconv();
echo number_format($amount, 2, $locale['decimal_point'], $locale['thousands_sep']);
Sign up to request clarification or add additional context in comments.

2 Comments

Is it working ? , if you keep $amount as 123456789 ( without .00 )
Really sorry, Please refer the following questions.. So, you can get the idea.. stackoverflow.com/questions/6369887/… stackoverflow.com/questions/9974704/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.