Re: Formatting Decimals
| From: | Rick Dwyer | Date: | Mon, 11 Jan 2010 19:55:33 +0000 |
| Subject: | Re: Formatting Decimals | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300993@lists.php.net to get a copy of this message | ||
I have been asked to further modify the value to the nearest half cent.
So if the 3rd decimal spot ends in 1 or 2, it gets rounded down to 0
If it ends in 3, 4, 5, 6 it gets rounded to 5. And if it 7, 8 or 9 it gets rounded up to full cents.
Can this be done fairly easily? Not knowing PHP well, I am not aware of the logic to configure this accordingly.
Thanks,
--Rick
On Jan 11, 2010, at 10:55 AM, Ryan Sun wrote:
$newprice = sprintf("$%.2f", 15.109); On Sun, Jan 10, 2010 at 8:36 PM, Rick Dwyer <rpdwyer@earthlink.net> wrote: Hello List. Probably an easy question, but I am not able to format a number to round up from 3 numbers after the decimal to just 2. My code looks like this: $newprice = "$".number_format($old_price, 2, ".", ","); and this returns "$0.109" when I am looking for "$0.11". I tried: $newprice = "$".round(number_format($old_price, 2, ".", ","),2); But no luck. Any help is appreciated. Thanks, --Rick --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php--Rick