Click to See Complete Forum and Search --> : decimal place problem


damon2003
01-16-2004, 08:52 AM
Hi,
I have 2 fields
one (hidden) contains a number with 2 decimal places, e.g. 45.00

the other is a textfield that contains a number that the user enter which will be an integer, i.e. 1 or 2 or 3 etc. It is a quantiy field so the user wont be entering any decimal places.

I have to multiply these two values together. At the moment, I lose 2 decimal places if the hidden field value contains zeros after the decimal point.

i.e. 45.00 * 1 becomed 45

How can I force 45.00 to stay as 45.00 even after multplying it by 1?
thanks

vertigo_one
01-16-2004, 09:24 AM
Maybe trying

$total = 45;

$total = floor($total, 2);

Khalid Ali
01-16-2004, 09:41 AM
you can sue string function

number_format($number,decimalPlacesInt,'format','')

which in your case may be like this
$num = 45.00 * 1;
number_format($num,2,".","");