]> granicus.if.org Git - icu/commitdiff
ICU-5938 Fix inaccurate output on RBNF demo sample (accuracy)
authorRobert Melo <robertgm@motorola.com>
Thu, 9 Apr 2020 13:47:38 +0000 (10:47 -0300)
committerSteven R. Loomis <srl295@gmail.com>
Sat, 11 Apr 2020 00:12:40 +0000 (17:12 -0700)
- In order to guarantee more accuracy on formatting, check
if number has fraction. If so, use double. Otherwise, use long.

icu4j/demos/src/com/ibm/icu/dev/demo/rbnf/RbnfDemo.java

index 4afa2ea39bee1c1c77b887019adb7043bb88cbd3..b08c68b1d60866ff94d89a8bb78970fe68720536 100644 (file)
@@ -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() {