Log in

View Full Version : Add code for decimal places



rhodarose
11-22-2010, 01:27 AM
Good day!

I want to know where I can put this code :


number_format($num), 2;


I have this code:


echo mysql_result ($result,$ctr,"inputqty");


I want the output if this code is in 2 decimal places for example the output in this code is: 1.9856211 I want to become is like this 1.99

I hope somebody can help me...thank you..

jscheuer1
11-22-2010, 02:27 AM
What's the output of echo mysql_result ($result,$ctr,"inputqty"); ? If it's a number and a number only and is always less than 1,000 (or if it's 1,000 or more, a comma's OK) then:


echo number_format(mysql_result ($result,$ctr,"inputqty"), 2);

But PHP sometimes doesn't like nesting, so to be on the safe side:


$num = mysql_result ($result,$ctr,"inputqty");
echo number_format($num, 2);

rhodarose
11-22-2010, 02:33 AM
What's the output of echo mysql_result ($result,$ctr,"inputqty"); ? If it's a number and a number only and is always less than 1,000 (or if it's 1,000 or more, a comma's OK) then:


echo number_format(mysql_result ($result,$ctr,"inputqty"), 2);

But PHP sometimes doesn't like nesting, so to be on the safe side:


$num = mysql_result ($result,$ctr,"inputqty");
echo number_format($num, 2);

Thank you...