Rounding and Display of Numeric Attributes

Document ID : KB000017679
Last Modified Date : 14/02/2018
Show Technical Document Details

Description:

When an Attribute (Numeric, 2 Decimal Places) Field is Set to Show Only 1 Decimal Place in the View & an Even Number is Entered into the 1st Decimal Place Followed by a 5 in the 2nd Decimal Place & Saved, Rounds Incorrectly

Steps to Reproduce:

  1. Login as Administrator
  2. Go to the Project Object
  3. Create a new attribute with Data Type = Number and Decimal Places = 2
  4. Go to the Application Side, and click on Projects
  5. Select the Configure Icon
  6. Move the attribute 'Num Test' from the Available Column to the Selected Column
  7. Save
  8. Click the List Column Section drop down, and select Fields
  9. Click on the Properties Icon for 'Num Test'
  10. Change Decimal Places to 1
  11. Save and Return to the Project List
  12. Now go back and perform an inline edit of the new 'Num Test' field to see the rounding correctly performed by entering 1.15 (note first place of the decimal is an odd number)
  13. Save
    See that the resulting number rounded up correctly to 1.2, as you would expect
  14. Now perform an in-line edit of the new 'Num Test' field to see the field round incorrectly by entering 1.25 (note first place of decimal is an even number):
  15. Save
    See that the resulting number rounded down incorrectly to 1.2 instead of 1.3 as you would expect 

Expected Result: .25 or any whole number with .25 displays as .3
Actual Result: .25 or any whole number with .25 displays as .2

Solution:

In general, we use the default Java rounding method which is called ROUND_HALF_EVEN is explained here.

http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html#ROUND_HALF_EVEN

Some examples here:

http://stackoverflow.com/questions/10144636/rounding-with-decimalformat-in-java

So .25 will round down while .35 will round up.