0

I want to set two decimal place. I have two numbers, one is 45 and other is 6.5. Now I want to print it like 45.00 and 6.50 I use php. Can any one help me?

My code is given below

<?php 
$a=45; $b=6.5;
echo ($a,2); echo ($b,2);
?>
Chattala
  • 1
  • 1

1 Answers1

1

Check out the number_format function:

$a = 45;
echo number_format($a, 2);
// prints out "45.00"
Briley Hooper
  • 1,271
  • 6
  • 16
  • $b=6.5 ; echo number_format($b,2); // print out "6.50" possible? – Chattala Jul 13 '17 at 05:39
  • Correct. Check out the link to the official PHP documentation for number_format, it goes into detail about all of the different ways the function can be used to format numbers. – Briley Hooper Jul 13 '17 at 05:43