How to convert money mask to php

Asked

Viewed 113 times

-2

I have the following value in real "513.40" wish that this value stay in full example 513.40000 with all rounding, how can I do this ?

  • Do you say convert a string into a float? If so, use floatval: http://php.net/manual/en/function.floatval.php

1 answer

0

in PHP there is the function money_format() that can be used like this:

echo money_format('%.2n', 12345.67);

money_format always starts with %. The .2 indicates that you always want to use two decimal places. If you pass an integer, it will add 0.00 at the end. The n indicates that you want to use the local national currency format.

It is important to note that you must define the location correctly, since money_format is based on the location you set for LC_MONETARY. To set the location, use setlocale. In this case, it seems that you want pt_BR.

setlocale(LC_MONETARY, 'pt_BR');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.