To display two decimals, use number_format(). Let us first write the PHP code for the same. We have first declared two variables are initialized −
$number1=10.3423; $number2=10;
Now, display the two decimals using the number_format() function −
$result1=number_format ($number1, 2); $result2=number_format ($number2, 2);
Example
Following is the example −
<?php $number1=10.3423; $number2=10; $result1=number_format ($number1, 2); $result2=number_format ($number2, 2); echo ($result1); echo '<br>'; echo ($result2); ?>
Output
Following is the snapshot of PHP code −
10.34 10.00