I have a value 3.9609053497942. I need value 3.9 means only one value after decimal. I have used PHP number_format and round functions but it is giving me answer 4.
Asked
Active
Viewed 72 times
1
-
Show your code with number_fromat – sectus Apr 09 '14 at 05:44
-
echo number_format(3.9609053497942,1); – user3454835 Apr 09 '14 at 05:45
5 Answers
2
You could multiply the number by 10, floor() it, and then divide it back.
echo floor($value * 10) / 10;
alex
- 460,746
- 196
- 858
- 974
1
Try with this,
echo intval((3.9609053497942*10))/10;
or
echo floor((3.9609053497942*10))/10;
Jenz
- 8,172
- 7
- 41
- 75
0
There is so many possible solutions:
echo bcadd(3.9609053497942, 0, 1);
preg_match('/\d*\.\d/', 3.9609053497942, $matches);
echo $matches[0];
sectus
- 15,278
- 5
- 51
- 91
-1
Did you tried like:
number_format(3.9609053497942, 1);
Elixir Techne
- 1,790
- 14
- 19
-
Yes it is not working. it is giving answer 4.0 but i need 3.9 answer – user3454835 Apr 09 '14 at 05:48