Page 1 of 1

Round output format problem!

Posted: Thu Nov 09, 2006 10:50 am
by pLachance
Hi there,

I do a simple round from a value of a MySQL result and i need to know how to keep the zeros....

Code: Select all

round($row->value,4)
if i have these values i get...

round(0.00001,4) => 0 .... but i want it to be displayed as 0.0000

is there a way to format the output of a round to keep the zeros? Other than doing a function to do so...

thx

Posted: Thu Nov 09, 2006 1:40 pm
by feyd
sprintf(), printf() and others can format it.

Posted: Thu Nov 09, 2006 1:53 pm
by pLachance
thx a lot! It was easy too! I searched but was unable to find that!
now it works pretty well with sprintf

$value = sprintf("%01.4f", round($row->value,4));

thx

Posted: Thu Nov 09, 2006 1:55 pm
by feyd
From what I remember, sprintf() will round it if needed.