View Single Post
  #4 (permalink)  
Old 07-11-04
Paul Knapp's Avatar
Paul Knapp Paul Knapp is offline
Registered User
 
Join Date: Aug 2003
Location: Kent
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Paul Knapp is an unknown quantity at this point
Why not store the number as a standard floating point, and only display to the screen the rounded number?

<?

$num = 4.215;

printf("Your rounded number is %01.1f to the nearest tenth",$num);

?>

If you DO want to store the rounded number, I would think sprintf was a much more robust (and faster) way to do it.

<?

$num = 4.215;

$rounded = sprintf("%01.1f",$num);

echo "<b>$num</b> to the nearest tenth is <b>$rounded</b>.";

?>
Reply With Quote
Sponsored Links