View Full Version : quick php "round" off question
ckevin
June 10th, 2002, 08:14
How can I round off integers so that it can have exactly 1 dec. place?
E.g. if I use PHP "round" command:
when the value is 4, the outcome is 4
the value is 4.123, the outcome is 4.1,
what I really want is value 4 --> outcome 4.0
value 4.123 --> outcome 4.1
Thanks!
bigperm
June 10th, 2002, 08:32
from php.net
float round ( float val [, int precision])
Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).
So it looks like
round (4, 1) will return 4.0
ckevin
June 11th, 2002, 11:17
bigperm, I have tried, but the outcome is "4" only...
<?
$row = round(4,1) ;
echo "$row" ;
?>
You can try yourself, and my php version is 4.0.6 :rolleyes:
Thanks!
Kevin
hohoho
June 11th, 2002, 11:18
try round(4, 2)
Dusty
June 11th, 2002, 14:43
Round won't do what you're trying to accomplish, use printf instead (or sprintf if you're doing something with the variable other than printing it).
printf("%.1f",$row);
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.