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
  • 769
  • 2
  • 9
  • 24

6 Answers6

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

You should try number_format():

$your_number = 5;

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

Manual

adrien
  • 4,399
  • 26
  • 26
1

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

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

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


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