Round Floating Point Number using PHP

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

Problem:- Round Floating Point Number using PHP. You want to round floating number, either to an integer value or to a set number of decimal places.

Solution – Round Floating Point Number using PHP

<?php
$float = 2.4;
$round_float = round($float);
printf("2.4 rounds to the float %s", $round_float);
?>

How it Works?

round() function is used to convert floating number into a real number like example above. round() function remove the decimal part like you have 2.4 so this function return 2 and if you have 2.5 or above than it will return 3.

इसे भी पढ़े – Compare Two Float Number using PHP

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *