How to display two decimals in MySQL/PHP?


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);

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);
?>

Following is the snapshot of PHP code −

Output

10.34
10.00



raja
Published on 13-Jun-2019 11:41:15
Advertisements