From: Robert Melo <robertgm@motorola.com>
Date: Thu, 9 Apr 2020 13:47:38 +0000 (-0300)
Subject: ICU-5938 Fix inaccurate output on RBNF demo sample (accuracy)
X-Git-Tag: cldr/2020-09-22~214
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2fc7f67c6bac0133395a9117e432a6737b2a6f38;p=icu

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.
---

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() {