0

Possible Duplicate:
simple regex in php, formatting decimal number

How to convert a digit in x format to x.xx format in php? example : I have a number 5. Need to convert to 5.00

Community
  • 1
  • 1
keerthi
  • 749
  • 2
  • 8
  • 23

6 Answers6

3
$n = 5;
$n = number_format($n, 2, '.', '');
C. Leung
  • 6,078
  • 3
  • 19
  • 32
2

You should try number_format():

$your_number = 5;

echo number_format($your_number, 2); // displays 5.00

Manual

adrien
  • 4,349
  • 24
  • 26
1

See http://php.net/manual/en/function.number-format.php

flowfree
  • 16,008
  • 12
  • 48
  • 75
1
number_format('your digit', 2 or 1, '.', '');
jugnu
  • 141
  • 6
0
 $number = 125

 $no = number_format($number, 2, '.', '');


 output = 125.00
Rinzler
  • 2,149
  • 1
  • 27
  • 44
0
$x = 5;
$x = sprintf('%.2f', $x);
echo $x;
Dejan Marjanović
  • 19,004
  • 7
  • 50
  • 66