开发者

Obtain Decimal values after Division

开发者 https://www.devze.com 2023-02-01 23:22 出处:网络
How can i obtain the decimal value after division ? after doing this days = miliseconds/(24 * 60 * 60 * 1000)

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

精彩评论

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