Jump to content

[SOLVED] numbe_format()


almightyegg

Recommended Posts

lol almightyegg. Guess that for your needs number_format() will work ok, but printf() is way more powerful. And yep 2 defines how many decimal space. If your number is ex. 23.456, using 2 as number of decimal spaces, it will print 23.457, rounding the last decimal digit.

Link to comment
Share on other sites

<?php
$x = 123.456;

echo number_format ($x, 2);     // 123.46
echo '<br/>';
echo sprintf ('%0.2f', $x);     // 123.46
?>

Both print a rounded result but AlmightyEgg seems to object to this. Hence my question - what does he want it to do?

 

I have a variable that can sometimes be a decimal, I wanted the regular numer_format() (, before every 3 digits) but number_format() rounded the number, say 456.34 to 456. and since looking on php.net/sprintf , I decided I'd go with the option that was easier for me, what guilty gear gave me :)

 

sprintf is so much cooler. And on another note these forums are freaking addicting when the wife is out of town and I've got nothing to do!

I don't have a wife but, I know wha you mean!! :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.