Accurax Posted September 19, 2008 Share Posted September 19, 2008 Hi guys, I hope this is a simple question.... i just cant find the answer atm. I have a set of cash vluse calculated from a base price and a percentage discount. Now, when this comes out at lets say 12.995 I would like to round this to 12.99 and not 13 as im currently getting .... is there any way of doing this? Really appreciate any help you can give Link to comment https://forums.phpfreaks.com/topic/124916-round-issue-should-be-straightforward-i-hope/ Share on other sites More sharing options...
zenag Posted September 19, 2008 Share Posted September 19, 2008 round(12.995,2) Link to comment https://forums.phpfreaks.com/topic/124916-round-issue-should-be-straightforward-i-hope/#findComment-645455 Share on other sites More sharing options...
GingerRobot Posted September 19, 2008 Share Posted September 19, 2008 Assuming you always want to round down the fraction of the penny then multiply by 100, round down, divide by 100: $var = 12.995; $var = floor($var*100)/100; echo $var; zenag, that will round to 13. A half rounds up. Link to comment https://forums.phpfreaks.com/topic/124916-round-issue-should-be-straightforward-i-hope/#findComment-645457 Share on other sites More sharing options...
kpetsche20 Posted September 19, 2008 Share Posted September 19, 2008 round(12.055, 2); // 12.06 Great article here. http://www.php.net/round Link to comment https://forums.phpfreaks.com/topic/124916-round-issue-should-be-straightforward-i-hope/#findComment-645458 Share on other sites More sharing options...
ranjuvs Posted September 19, 2008 Share Posted September 19, 2008 Try this $val = 12.995; $val = number_format($val,2); Link to comment https://forums.phpfreaks.com/topic/124916-round-issue-should-be-straightforward-i-hope/#findComment-645463 Share on other sites More sharing options...
GingerRobot Posted September 19, 2008 Share Posted September 19, 2008 Try this $val = 12.995; $val = number_format($val,2); Also rounds to 13. The number_format() function performs a round if necessary. Link to comment https://forums.phpfreaks.com/topic/124916-round-issue-should-be-straightforward-i-hope/#findComment-645465 Share on other sites More sharing options...
ranjuvs Posted September 19, 2008 Share Posted September 19, 2008 hmm I c.. Thanks Gingerbot, for correcting me Link to comment https://forums.phpfreaks.com/topic/124916-round-issue-should-be-straightforward-i-hope/#findComment-645467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.