Reputation: 7109
I am having trouble thinking of a php function to add zeros after a decimal. Let say I have $money="10000" I need a function that will add .00 to 10000.00 and to add just a zero to 0 after 234.5. can anyone help me please?
Upvotes: 6
Views: 20337
Reputation: 350
Just as Dan Grossman said; number_format is your friend here and you'd accomplish those double zeros by:
$money = "1234";
$formatedNumber = number_format($money, 2, '.', '');
echo $formatedNumber;
// 1234.00
Upvotes: 14
Reputation: 12381
Maybe not the answer you want to hear, but I think you're better off storing these values in numeric types and formatting them properly just before output
Upvotes: 1
Reputation: 52372
The function is number_format
http://php.net/manual/en/function.number-format.php
Always search the PHP manual first :)
Upvotes: 9