2

Thank you if you help me to solve this. I need this round up with 2 decimal

<? echo round(ceil((0.55*100))/100,2); // output 0.56 ?>

I want this

0.050 -> 0.05

0.051 -> 0.06

0.055 -> 0.06

0.059 -> 0.06

0.060 -> 0.06

Thank you!

Nuno
  • 21
  • 1
  • `round(ceil((0.55*100))/100,1);` this? – Sfili_81 Nov 13 '20 at 16:00
  • I wonder why `ceil()` doesn't provide a `precision` argument like `round()` oO – Daniel W. Nov 13 '20 at 16:04
  • Also [PHP Round function - round up to 2 dp?](https://stackoverflow.com/questions/6426799/php-round-function-round-up-to-2-dp) – Daniel W. Nov 13 '20 at 16:06
  • See the [round()](https://www.php.net/manual/en/function.round.php) function: ` echo round(0.55, 2, PHP_ROUND_HALF_DOWN); // output 0.55 ?>`. – KIKO Software Nov 13 '20 at 16:08
  • I just finished answering your question when I discovered that people had hastily closed your question and I got a phone call at the same time. Does the above comment help? – KIKO Software Nov 13 '20 at 16:20
  • All replies is incorrect. Please validate values – Nuno Nov 13 '20 at 16:25
  • Help please. Thank you – Nuno Nov 13 '20 at 16:27
  • Your code seems to work for all of the examples you provided. `$num = .052; $round = round(ceil(($num*100))/100,2); echo $num.' rounded to '.$round;` outputs `0.052 rounded to 0.06`. All of your examples to the hundredths place work as expected. Are you looking for a function that will round `.55` to `.6` AND `.055` to `.06`? – WOUNDEDStevenJones Nov 13 '20 at 16:33
  • WOUNDEDStevenJones it works... but try with $num = 0.55 – Nuno Nov 13 '20 at 16:49
  • Unclear, your rather minimal code example doesn't match the output values required; 0.55 or 0.055? – Maarten Bodewes Nov 14 '20 at 00:49

0 Answers0