From: Stuart G. <icu...@gm...> - 2011-01-26 23:13:55
|
I have done some investigation on the issue from today's ICU meeting on the rounding up of small numbers between -1 and 0 exclusive to -0. http://bugs.icu-project.org/trac/ticket/8302 It appears that this change to the rounding behaviour was done in response to http://bugs.icu-project.org/trac/ticket/7609 This change also appears to be to match JDK behaviour. So, in the following code taken from NumberFormatTest.java (DecimalFormat below is com.ibm.icu.text.DecimalFormat): DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); df.setRoundingMode(MathContext.ROUND_HALF_UP); // whether the rounding is set or not the result is the same df.setMinimumFractionDigits(1); df.setMaximumFractionDigits(1); String text1 = df.format(-0.01); The contents of text1 are "-0". This is the same for this JDK code: java.text.DecimalFormat jdf = (java.text.DecimalFormat) java.text.NumberFormat.getInstance(); //jdf.setRoundingMode(MathContext.ROUND_HALF_UP); jdf.setMinimumFractionDigits(1); jdf.setMaximumFractionDigits(1); String jtext1 = jdf.format(-0.01); The contents of jtext1 are "-0". So, this still leaves the question open then of what should a user do if they don't want "-0" but instead want what perhaps 99% of users want which is "0" all the time? Is there an existing way to do this? If not, perhaps we need API to do so? Thanks, Stuart |