AV1611 Posted September 5, 2008 Share Posted September 5, 2008 I need to round up to the nearest dollar so for example $51,000.01 would be 52,000.00 Doesn't seem to be a way? do I need to add like $499.99 to the value then round to the nearest instead? or is there an easier way? Thanks. Link to comment https://forums.phpfreaks.com/topic/122808-round-up/ Share on other sites More sharing options...
rarebit Posted September 5, 2008 Share Posted September 5, 2008 add half a unit (whatever you want to round to) then round down... Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634164 Share on other sites More sharing options...
DarkWater Posted September 5, 2008 Share Posted September 5, 2008 That's not rounding up by dollars, it's rounding up by thousands. You could do: <?php $val = 51000.01; $newval = ceil($val * pow(10, -3)) * pow(10, 3); echo $newval; ?> Yay math! And to add the .00 back, just use like, number_format(). Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634167 Share on other sites More sharing options...
AV1611 Posted September 5, 2008 Author Share Posted September 5, 2008 just checking... how can I make it a function (I suck at functions...) ty. Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634168 Share on other sites More sharing options...
DarkWater Posted September 5, 2008 Share Posted September 5, 2008 <?php function ceil_nearest($number, $power) { if ($power < 1) { return false; } return ceil($number * pow(10, ($power * -1))) * pow(10, $power); } All you need to know is powers of 10. Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634169 Share on other sites More sharing options...
dezkit Posted September 5, 2008 Share Posted September 5, 2008 All you need to know is powers of 10. Is there a article about that on php.net ? Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634170 Share on other sites More sharing options...
DarkWater Posted September 5, 2008 Share Posted September 5, 2008 I think an 8th grade algebra class would suffice, dezkit. If you really want me to explain them, PM me. =/ Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634172 Share on other sites More sharing options...
AV1611 Posted September 5, 2008 Author Share Posted September 5, 2008 <?php function ceil_nearest($number, $power) { if ($power < 1) { return false; } return ceil($number * pow(10, ($power * -1))) * pow(10, $power); } All you need to know is powers of 10. thank you Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634174 Share on other sites More sharing options...
DarkWater Posted September 5, 2008 Share Posted September 5, 2008 Change it to: <?php function ceil_nearest($number, $power) { if ($power < 1) { return false; } elseif (pow(10, $power) > $number) { return pow(10, $power); } return ceil($number * pow(10, ($power * -1))) * pow(10, $power); } Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634175 Share on other sites More sharing options...
jordanwb Posted September 5, 2008 Share Posted September 5, 2008 Is there a article about that on php.net ? Why would there be an article on this? I think an 8th grade algebra class would suffice, dezkit. If you really want me to explain them, PM me. =/ Owned. Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634179 Share on other sites More sharing options...
DarkWater Posted September 5, 2008 Share Posted September 5, 2008 Is there a article about that on php.net ? Why would there be an article on this? I think an 8th grade algebra class would suffice, dezkit. If you really want me to explain them, PM me. =/ Owned. Lol, I know, right? xD Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634180 Share on other sites More sharing options...
The Little Guy Posted September 5, 2008 Share Posted September 5, 2008 give this a try: http://phpsnips.com/snippet.php?id=58 Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634236 Share on other sites More sharing options...
jordanwb Posted September 5, 2008 Share Posted September 5, 2008 ^ +1 for that one. Link to comment https://forums.phpfreaks.com/topic/122808-round-up/#findComment-634238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.