android - Rounding errors in Java -


i'm having rounding issues in java (i.e. whole = 1387.583515625 output x = 5836 instead of 5835. have searched issue before , i've tried various of answers still can't seem yo work. ideas?

decimalformat df = new decimalformat(".####"); df.setroundingmode(roundingmode.ceiling);  int x = integer.parseint(string.format(df.format(whole)).split("\\.")[1]); 

look @ table decide want https://docs.oracle.com/javase/7/docs/api/java/math/roundingmode.html

df.setroundingmode(roundingmode.half_up); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -