How to add numbers after decimal number using php

I am having trouble understanding the php function to add zeros after a decimal number. Let's say I have $ money = "10000" I need a function that will add from 100 to 10000.00 and add only zero to 0 after 234.5. can someone help me?

+3
source share
3 answers

Number_format function

http://php.net/manual/en/function.number-format.php

Always find the PHP manual first :)

+8
source

Just as Dan Grossman said; number_format is your friend here and you will achieve these double zeros:

$money = "1234";
$formatedNumber = number_format($money, 2, '.', '');
echo $formatedNumber;

// 1234.00
+3
source

, , , ,

0

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


All Articles