Java rounding

Rounding mode:
http://java.sun.com/javase/6/docs/api/java/math/RoundingMode.html

Code Example:

double result1 = new BigDecimal(String.valueOf(12.115)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
double result2 = new BigDecimal(String.valueOf(-12.115)).setScale(2, BigDecimal.ROUND_CEILING).doubleValue();

發表迴響

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

連結到 %s

Follow

Get every new post delivered to your Inbox.