View Single Post
Old 02-05-2009, 08:06 PM   #6 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Edit: D'oh, you beat me too it

First we move the decimal point one place to the left (by dividing it by 10), then sprintf formats the result.

%0.1F (or %.nF) == format the value given as a floating point number (F) to one decimal place (0.1, the number after the . is the number of places, so %.4F would be to 4 decimal places and so on).

An alternative way (and a lot less elegant)
PHP Code:
echo round($row['cargo_11'] / 101); 
sprintf is a very powerful and useful function.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote