From 2fc7f67c6bac0133395a9117e432a6737b2a6f38 Mon Sep 17 00:00:00 2001 From: Robert Melo Date: Thu, 9 Apr 2020 10:47:38 -0300 Subject: [PATCH] ICU-5938 Fix inaccurate output on RBNF demo sample (accuracy) - In order to guarantee more accuracy on formatting, check if number has fraction. If so, use double. Otherwise, use long. --- .../demos/src/com/ibm/icu/dev/demo/rbnf/RbnfDemo.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/icu4j/demos/src/com/ibm/icu/dev/demo/rbnf/RbnfDemo.java b/icu4j/demos/src/com/ibm/icu/dev/demo/rbnf/RbnfDemo.java index 4afa2ea39be..b08c68b1d60 100644 --- a/icu4j/demos/src/com/ibm/icu/dev/demo/rbnf/RbnfDemo.java +++ b/icu4j/demos/src/com/ibm/icu/dev/demo/rbnf/RbnfDemo.java @@ -116,8 +116,9 @@ public class RbnfDemo extends DemoApplet { textField.setText("PARSE ERROR"); } else { - theNumber = new BigDecimal(fieldText); - textField.setText(spelloutFormatter.format(theNumber.doubleValue(), ruleSetName)); + theNumber = new BigDecimal(temp instanceof Long ? temp.longValue() : temp.doubleValue()); + textField.setText(spelloutFormatter.format( + theNumber.scale() == 0 ? theNumber.longValue() : theNumber.doubleValue(), ruleSetName)); } } } ); @@ -243,7 +244,8 @@ public class RbnfDemo extends DemoApplet { numberField.setText(numberFormatter.format(theNumber)); numberField.selectAll(); - textField.setText(spelloutFormatter.format(theNumber.doubleValue(), ruleSetName)); + textField.setText(spelloutFormatter + .format(theNumber.scale() == 0 ? theNumber.longValue() : theNumber.doubleValue(), ruleSetName)); Panel leftPanel = new Panel(); leftPanel.setLayout(new BorderLayout()); @@ -412,7 +414,8 @@ public class RbnfDemo extends DemoApplet { void redisplay() { numberField.setText(numberFormatter.format(theNumber)); - textField.setText(spelloutFormatter.format(theNumber.doubleValue(), ruleSetName)); + textField.setText(spelloutFormatter + .format(theNumber.scale() == 0 ? theNumber.longValue() : theNumber.doubleValue(), ruleSetName)); } void makeNewSpelloutFormatter() {