0

I have number like '5.5'. we want to display like '5.500'. I could use number format function for this. But it is returning string.

$total_charges =number_format((float)$number, 3, '.', ''); 

When I use string value in mongodb so its not sort or filter in proper way.

array('total_charges'=>array('$gte'=>100,'$lte'=>200))

There is any function like number format that return numeric value with particular decimal places.

nitin
  • 1
  • 1
  • you don't need to store `5.500`. Store it as 5.5. When your re-tribe it to client hand then use number format to show like 5.500 – Payer Ahammed Oct 10 '15 at 12:21

2 Answers2

0

"5.500" simply cannot be a number. This is a representation of a number. You said yourself "we want to display like" !

minychillo
  • 395
  • 4
  • 17
0
echo sprintf("%1\$.3f",1.25);

the result is : 1.250

neojos
  • 1
  • 1
  • echo sprintf("%6.3f",22.25); the function return a float number,the 6 present will display 6 number,include '.',the 3 present the after '.' have 3 number – neojos Oct 12 '15 at 01:52
  • `echo sprintf()` is an "antipattern". There is absolutely no reason that anyone should ever write `echo sprintf()` -- it should be `printf()` without `echo` every time. – mickmackusa Apr 16 '22 at 02:21