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 Quote Link to comment Share on other sites More sharing options...
zenag Posted September 19, 2008 Share Posted September 19, 2008 round(12.995,2) Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.