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 80 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
- 479,566
- 201
- 878
- 984
1
Try with this,
echo intval((3.9609053497942*10))/10;
or
echo floor((3.9609053497942*10))/10;

Jenz
- 8,280
- 7
- 44
- 77
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,605
- 5
- 55
- 97
-1
Did you tried like:
number_format(3.9609053497942, 1);

Elixir Techne
- 1,848
- 15
- 20
-
Yes it is not working. it is giving answer 4.0 but i need 3.9 answer – user3454835 Apr 09 '14 at 05:48