View Full Version : Math Help

11-07-2012, 05:27 PM
Hey all,

I was wondering when you come up with a addition or subtraction of numbers with a decimal how you can get the zero or zeros to show up.

eg.. instead of 139.9

I would like to see 139.90

or instead of 300.

I would like to see 300.00

Hope ya understand..

Thanks in advance.


11-07-2012, 06:05 PM
Use a print formatter:

printf("%0.2f", 139.9);

If its for monies, then using money_format would be better if you have it available since its locale aware. No matter the case, having 139.90 instead of 139.9 is the difference between (string)139.90 and (double)139.9.

11-07-2012, 09:09 PM
or number_format (http://php.net/manual/en/function.number-format.php)