Round output format problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pLachance
Forum Newbie
Posts: 4
Joined: Tue Nov 07, 2006 10:28 am

Round output format problem!

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sprintf(), printf() and others can format it.
pLachance
Forum Newbie
Posts: 4
Joined: Tue Nov 07, 2006 10:28 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

From what I remember, sprintf() will round it if needed.
Post Reply