This topic is locked

Rounding up a figure

2/10/2009 2:02:27 PM
PHPRunner General questions
S
swanside author

I have a db that charts weight by using this sum

(select Start_Weight*0.0714285714286) AS Weight_in_Stones,


It returns this figure when I use view as custom and have

$value=$value." st";


16.285714285721 st.
How can I round it up to just say 16.28 st
Thanks

hichem 2/10/2009

I have a db that charts weight by using this sum


(select Start_Weight*0.0714285714286) AS Weight_in_Stones,


It returns this figure when I use view as custom and have

$value=$value." st";


16.285714285721 st.
How can I round it up to just say 16.28 st
Thanks


depending on your RDBMS you would have to use a different function, in mysql use truncate(field,2) it should truncate the field to 2 decimals. so in your case: select truncate((start_weight*0.0714285714286),2) as weight_in_stones

hope this helps

A
alang 2/10/2009

Another suggestion would be to use the PHP sprintf function.