Home > Software engineering >  How to RoundDown for second digit in PHP?
How to RoundDown for second digit in PHP?

Time:03-03

I want to round down for second digit. For example, the number is 12250, I want to round down it to 12200. In PHP, I'm aware that there functions floor(), ceil() functions to make this work but that's working only for floating numbers.

Can anyone please help?

CodePudding user response:

You can divide the number with 100 (will give you 122.50), then use floor() (will give you 122.00) and multiply it with 100 again (will give you 12200)

$number = 12250;
$number = floor($number / 100) * 100;

Here's a demo: https://3v4l.org/Eiiqh

CodePudding user response:

You can also subtract the remainder when dividing by 100.

$number = 12250;
$number -= $number0;  //int(12000)
  • Related