How to Properly Specify Rounding Behavior for Decimals in Java SE 8 (Doc ID 2285184.1)

Last updated on JULY 16, 2017

Applies to:

Java SE JDK and JRE - Version 8 and later
Information in this document applies to any platform.

Goal

You might have a program that uses the decimalFormat class for rounding arbitrary decimal values.  The following sample code illustrates the technique:

 

Is this a bug in Java SE?  How can you get the correct rounding results expected?

Solution

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms