I am calculating the speed and number of calories burned in my app for which I have to convert this number 7.813094473379822E-4 to just 7. How should I convert this? Can anyone help me?
Asked
Active
Viewed 203 times
-1
-
1Possible duplicate of [Converting BigDecimal to Integer](http://stackoverflow.com/questions/4043579/converting-bigdecimal-to-integer) – IIIIIIIIIIIIIIIIIIIIII Nov 23 '16 at 14:45
-
1`7.813094473379822E-4` does not equal `7`, so why would you want to make it `7`? Converting this value to an integer would result in `0`. – Bryan Nov 23 '16 at 14:55
-
kk so can i round it to 8 – sai pavan Nov 23 '16 at 15:10
-
@saipavan: no not "round it to 8". You don't seem to understand that `7.81...E-4` is another way to write `0.000781...`. Rounding that to an integer results in `0`, not `7` or `8`. – Rudy Velthuis Nov 25 '16 at 15:59
-
i really lost my mind, thanks a lot for making me understand – sai pavan Nov 27 '16 at 12:40
1 Answers
2
To get the integer value from a
BigDecimal
instance you can use BigDecimal#intValue()

cjungel
- 3,701
- 1
- 25
- 19