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

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

Updated on: 31-Dec-2019

225 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements