PHP in HindiProgramming Language

Round Floating Point Number using PHP

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.

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button
Close