Convert integer strings to money format

I have a set of integers that I would like to change to the US money format.

Here are some examples of what I would like to do. The first number is what is in the database, and the second is what I would like the money format to look like.

4500 = $ 45.00

395 = $ 3.95

19000 = $ 190.00

I really just don't know what function I should use to do such a conversion.

thanks for the help

+3
source share
4 answers

You can use number_format ()

number_format((4500/100), 2);

There's also money_format () , but it's a little trickier.

+3
source
+2
$number=4500;
$money='$'.round($number/100,2);
+1

Have you looked at money_format () ? You just need to divide your values ​​by 100 before using them with this function.

Alternatively, you can consider number_format () .

0
source

Source: https://habr.com/ru/post/1716118/


All Articles