PDA

View Full Version : having 2 zero's at the end of a number


grudz
05-04-2005, 09:57 PM
Hi,

I have a script that calculates the total of 2 numbers

Ex: 500.00 + 275.50 = $amount

then it prints the $amount as 775.5

I would like it to be 775.50....meaning that it always has 2 numbers after the . (instead of only 1 if there is, and if there isn't any numbers it'll be 775)

How can I do that?

Thank you

Velox Letum
05-04-2005, 10:14 PM
Edited, I wasn't thinking...again


$price = '34.2';
$eprice = explode('.', $price)
if (strlen($eprice) == 1) {
$price = $price . '0';
}

Rough, and theres probably an easier way to do it.

marek_mar
05-04-2005, 11:11 PM
...
<?php
print number_format(14555.65676854, 2, '.', '');
?>

grudz
05-05-2005, 01:34 AM
hey marek_mar,

what if the number is a variable


print number_format($total, 2, '.', '');


basically i want the total to always have 2 numbers after the "."

Velox Letum
05-05-2005, 04:01 AM
Once again I find myself kicking my person for not thinking. The $total variable should work as long as its set.