简体   繁体   中英

Rounding decimal number only last two digit PHP

I have to round of only last two digits near 10 in PHP.

For example 0.27777777777778 ->0.30

0.47777777777778 ->0.50

0.57777777777778 ->0.60

$input=0.27777777777778;
$number = number_format(round($input,1),2);
echo $number;

Round your number to 0.3, then use number format to show two decimal points.

From the PHP manual / docs:

  • Rounding numbers - Link
  • Number format - Link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM