开发者

Obtain Decimal values after Division

How can i obtain the decimal value after division ? after doing this

days = miliseconds/(24 * 60 * 60 * 1000)

suppose the value(i.e days) is 27.8351 how do i get 8351 ? Tried

hours = days % (int) days thought it s doing 27.8351 / 27 but still it returned 开发者_开发技巧a big Zero, havent tried converting it into string and then splitting based on DOT (.) but i dont like this way have i over looked some thing ?


You should use BigDecimal for this kind of operations. The divideAndRemainder method is available.


hours = (days - (int) days) * 10000

(to get 4 digits after decimal)


There are many ways to do this.

If you know in advance the number of decimal places, then subtract the result by the whole number and multiply it 10 to power of the number of decimal places.

Example: # of dec places is 4 and the result is 42.8798

Process:

(1) 42.8798 - 42 = 0.8798

(2) 0.8798 * (10^4) = 8978

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜