1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // 2016 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 /***************************************************************************************** 5 * 6 * Copyright (C) 1996-2016, International Business Machines 7 * Corporation and others. All Rights Reserved. 8 **/ 9 10 /** 11 * Port From: JDK 1.4b1 : java.text.Format.NumberRegression 12 * Source File: java/text/format/NumberRegression.java 13 **/ 14 15 /** 16 * @test 1.49 01/05/21 17 * @bug 4052223 4059870 4061302 4062486 4066646 4068693 4070798 4071005 4071014 18 * 4071492 4071859 4074454 4074620 4075713 4083018 4086575 4087244 4087245 19 * 4087251 4087535 4088161 4088503 4090489 4090504 4092480 4092561 4095713 20 * 4098741 4099404 4101481 4106658 4106662 4106664 4108738 4110936 4122840 21 * 4125885 4134034 4134300 4140009 4141750 4145457 4147295 4147706 4162198 22 * 4162852 4167494 4170798 4176114 4179818 4185761 4212072 4212073 4216742 23 * 4217661 4243011 4243108 4330377 4233840 24 * @summary Regression tests for NumberFormat and associated classes 25 */ 26 27 package android.icu.dev.test.format; 28 29 import java.io.ByteArrayInputStream; 30 import java.io.ByteArrayOutputStream; 31 import java.io.IOException; 32 import java.io.ObjectInputStream; 33 import java.io.ObjectOutputStream; 34 import java.io.Serializable; 35 import java.math.BigInteger; 36 import java.text.FieldPosition; 37 import java.text.ParseException; 38 import java.text.ParsePosition; 39 import java.util.Date; 40 import java.util.Locale; 41 42 import org.junit.Test; 43 import org.junit.runner.RunWith; 44 import org.junit.runners.JUnit4; 45 46 import android.icu.dev.test.TestFmwk; 47 import android.icu.impl.ICUData; 48 import android.icu.impl.ICUResourceBundle; 49 import android.icu.text.DateFormat; 50 import android.icu.text.DecimalFormat; 51 import android.icu.text.DecimalFormatSymbols; 52 import android.icu.text.NumberFormat; 53 import android.icu.util.GregorianCalendar; 54 import android.icu.util.ULocale; 55 import android.icu.util.VersionInfo; 56 import android.icu.testsharding.HiMemTestShard; 57 58 @HiMemTestShard 59 @RunWith(JUnit4.class) 60 public class NumberRegressionTests extends TestFmwk { 61 private static final char EURO = '\u20ac'; 62 63 /** 64 * NumberFormat.equals comparing with null should always return false. 65 */ 66 @Test 67 public void Test4075713(){ 68 69 try { 70 MyNumberFormat tmp = new MyNumberFormat(); 71 if (!tmp.equals(null)) 72 logln("NumberFormat.equals passed"); 73 } catch (NullPointerException e) { 74 errln("(new MyNumberFormatTest()).equals(null) throws unexpected exception"); 75 } 76 } 77 78 /** 79 * NumberFormat.equals comparing two obj equal even the setGroupingUsed 80 * flag is different. 81 */ 82 @Test 83 public void Test4074620() { 84 85 MyNumberFormat nf1 = new MyNumberFormat(); 86 MyNumberFormat nf2 = new MyNumberFormat(); 87 88 nf1.setGroupingUsed(false); 89 nf2.setGroupingUsed(true); 90 91 if (nf1.equals(nf2)) errln("Test for bug 4074620 failed"); 92 else logln("Test for bug 4074620 passed."); 93 return; 94 } 95 96 97 /** 98 * DecimalFormat.format() incorrectly uses maxFractionDigits setting. 99 */ 100 @Test 101 public void Test4088161 (){ 102 DecimalFormat df = new DecimalFormat(); 103 double d = 100; 104 df.setMinimumFractionDigits(0); 105 df.setMaximumFractionDigits(16); 106 StringBuffer sBuf1 = new StringBuffer(""); 107 FieldPosition fp1 = new FieldPosition(0); 108 logln("d = " + d); 109 logln("maxFractionDigits = " + df.getMaximumFractionDigits()); 110 logln(" format(d) = '" + df.format(d, sBuf1, fp1) + "'"); 111 df.setMaximumFractionDigits(17); 112 StringBuffer sBuf2 = new StringBuffer(""); 113 FieldPosition fp2 = new FieldPosition(0); 114 logln("maxFractionDigits = " + df.getMaximumFractionDigits()); 115 df.format(d, sBuf2, fp2); 116 if (!sBuf2.toString().equals("100")) 117 errln(" format(d) = '" + sBuf2 + "'"); 118 } 119 /** 120 * DecimalFormatSymbols should be cloned in the ctor DecimalFormat. 121 * DecimalFormat(String, DecimalFormatSymbols). 122 */ 123 @Test 124 public void Test4087245 (){ 125 DecimalFormatSymbols symbols = new DecimalFormatSymbols(); 126 DecimalFormat df = new DecimalFormat("#,##0.0", symbols); 127 long n = 123; 128 StringBuffer buf1 = new StringBuffer(); 129 StringBuffer buf2 = new StringBuffer(); 130 logln("format(" + n + ") = " + 131 df.format(n, buf1, new FieldPosition(0))); 132 symbols.setDecimalSeparator('p'); // change value of field 133 logln("format(" + n + ") = " + 134 df.format(n, buf2, new FieldPosition(0))); 135 if (!buf1.toString().equals(buf2.toString())) 136 errln("Test for bug 4087245 failed"); 137 } 138 /** 139 * DecimalFormat.format() incorrectly formats 0.0 140 */ 141 @Test 142 public void Test4087535 () 143 { 144 DecimalFormat df = new DecimalFormat(); 145 df.setMinimumIntegerDigits(0); 146 147 double n = 0; 148 String buffer = new String(); 149 buffer = df.format(n); 150 if (buffer.length() == 0) 151 errln(n + ": '" + buffer + "'"); 152 n = 0.1; 153 buffer = df.format(n); 154 if (buffer.length() == 0) 155 errln(n + ": '" + buffer + "'"); 156 } 157 158 /** 159 * DecimalFormat.format fails when groupingSize is set to 0. 160 */ 161 @Test 162 public void Test4088503 (){ 163 DecimalFormat df = new DecimalFormat(); 164 df.setGroupingSize(0); 165 StringBuffer sBuf = new StringBuffer(""); 166 FieldPosition fp = new FieldPosition(0); 167 try { 168 logln(df.format(123, sBuf, fp).toString()); 169 } catch (Exception foo) { 170 errln("Test for bug 4088503 failed: " + foo); 171 } 172 173 } 174 /** 175 * NumberFormat.getCurrencyInstance is wrong. 176 */ 177 @Test 178 public void Test4066646 () { 179 //float returnfloat = 0.0f; //The variable is never used 180 assignFloatValue(2.04f); 181 assignFloatValue(2.03f); 182 assignFloatValue(2.02f); 183 assignFloatValue(0.0f); 184 } 185 186 public float assignFloatValue(float returnfloat) 187 { 188 logln(" VALUE " + returnfloat); 189 NumberFormat nfcommon = NumberFormat.getCurrencyInstance(Locale.US); 190 nfcommon.setGroupingUsed(false); 191 192 String stringValue = nfcommon.format(returnfloat).substring(1); 193 if (Float.valueOf(stringValue).floatValue() != returnfloat) 194 errln(" DISPLAYVALUE " + stringValue); 195 return returnfloat; 196 } // End Of assignFloatValue() 197 198 /** 199 * DecimalFormat throws exception when parsing "0" 200 */ 201 @Test 202 public void Test4059870() { 203 DecimalFormat format = new DecimalFormat("00"); 204 try { 205 logln(format.parse("0").toString()); 206 } catch (Exception e) { errln("Test for bug 4059870 failed : " + e); } 207 } 208 /** 209 * DecimalFormatSymbol.equals should always return false when 210 * comparing with null. 211 */ 212 213 @Test 214 public void Test4083018 (){ 215 DecimalFormatSymbols dfs = new DecimalFormatSymbols(); 216 try { 217 if (!dfs.equals(null)) 218 logln("Test Passed!"); 219 } catch (Exception foo) { 220 errln("Test for bug 4083018 failed => Message : " + foo.getMessage()); 221 } 222 } 223 /** 224 * DecimalFormat does not round up correctly. 225 */ 226 @Test 227 public void Test4071492 (){ 228 double x = 0.00159999; 229 NumberFormat nf = NumberFormat.getInstance(); 230 nf.setMaximumFractionDigits(4); 231 String out = nf.format(x); 232 logln("0.00159999 formats with 4 fractional digits to " + out); 233 String expected = "0.0016"; 234 if (!out.equals(expected)) 235 errln("FAIL: Expected " + expected); 236 } 237 238 /** 239 * A space as a group separator for localized pattern causes 240 * wrong format. WorkAround : use non-breaking space. 241 */ 242 @Test 243 public void Test4086575() { 244 245 NumberFormat nf = NumberFormat.getInstance(Locale.FRANCE); 246 logln("nf toPattern1: " + ((DecimalFormat)nf).toPattern()); 247 logln("nf toLocPattern1: " + ((DecimalFormat)nf).toLocalizedPattern()); 248 249 // No group separator 250 logln("...applyLocalizedPattern ###,00;(###,00) "); 251 ((DecimalFormat)nf).applyLocalizedPattern("###,00;(###,00)"); 252 logln("nf toPattern2: " + ((DecimalFormat)nf).toPattern()); 253 logln("nf toLocPattern2: " + ((DecimalFormat)nf).toLocalizedPattern()); 254 255 logln("nf: " + nf.format(1234)); // 1234,00 256 logln("nf: " + nf.format(-1234)); // (1234,00) 257 258 // Space as group separator 259 260 logln("...applyLocalizedPattern # ###,00;(# ###,00) "); 261 ((DecimalFormat)nf).applyLocalizedPattern("#\u00a0###,00;(#\u00a0###,00)"); 262 logln("nf toPattern2: " + ((DecimalFormat)nf).toPattern()); 263 logln("nf toLocPattern2: " + ((DecimalFormat)nf).toLocalizedPattern()); 264 String buffer = nf.format(1234); 265 if (!buffer.equals("1\u00a0234,00")) 266 errln("nf : " + buffer); // Expect 1 234,00 267 buffer = nf.format(-1234); 268 if (!buffer.equals("(1\u00a0234,00)")) 269 errln("nf : " + buffer); // Expect (1 234,00) 270 271 // Erroneously prints: 272 // 1234,00 , 273 // (1234,00 ,) 274 275 } 276 /** 277 * DecimalFormat.parse returns wrong value 278 */ 279 @Test 280 public void Test4068693() 281 { 282 logln("----- Test Application -----"); 283 //ParsePosition pos; 284 DecimalFormat df = new DecimalFormat(); 285 Number d = df.parse("123.55456", new ParsePosition(0)); 286 if (!d.toString().equals("123.55456")) { 287 errln("Result -> " + d.doubleValue()); 288 } 289 } 290 291 /* bugs 4069754, 4067878 292 * null pointer thrown when accessing a deserialized DecimalFormat 293 * object. 294 */ 295 @Test 296 public void Test4069754() throws Exception 297 { 298 //try { 299 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 300 ObjectOutputStream oos = new ObjectOutputStream(baos); 301 myformat it = new myformat(); 302 logln(it.Now()); 303 oos.writeObject(it); 304 oos.flush(); 305 baos.close(); 306 logln("Save OK!"); 307 byte [] bytes = baos.toByteArray(); 308 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); 309 myformat o = (myformat)ois.readObject(); 310 ois.close(); 311 it.Now(); 312 logln("Load OK!"); 313 if (!o._dateFormat.equals(it._dateFormat)) { 314 throw new Exception("The saved and loaded object are not equals!"); 315 } 316 logln("Compare OK!"); 317 //} catch (Exception foo) { 318 //errln("Test for bug 4069754 or 4057878 failed => Exception: " + foo.getMessage()); 319 //} 320 } 321 322 /** 323 * DecimalFormat.applyPattern(String) allows illegal patterns 324 */ 325 @Test 326 public void Test4087251 (){ 327 DecimalFormat df = new DecimalFormat(); 328 try { 329 df.applyPattern("#.#.#"); 330 logln("toPattern() returns \"" + df.toPattern() + "\""); 331 errln("applyPattern(\"#.#.#\") doesn't throw IllegalArgumentException"); 332 } catch (IllegalArgumentException e) { 333 logln("Caught Illegal Argument Error !"); 334 } 335 // Second test; added 5/11/98 when reported to fail on 1.2b3 336 try { 337 df.applyPattern("#0.0#0#0"); 338 logln("toPattern() returns \"" + df.toPattern() + "\""); 339 errln("applyPattern(\"#0.0#0#0\") doesn't throw IllegalArgumentException"); 340 } catch (IllegalArgumentException e) { 341 logln("Ok - IllegalArgumentException for #0.0#0#0"); 342 } 343 } 344 345 /** 346 * DecimalFormat.format() loses precision 347 */ 348 @Test 349 public void Test4090489 (){ 350 DecimalFormat df = new DecimalFormat(); 351 df.setMinimumFractionDigits(10); 352 df.setGroupingUsed(false); 353 double d = 1.000000000000001E7; 354 java.math.BigDecimal bd = new java.math.BigDecimal(d); 355 StringBuffer sb = new StringBuffer(""); 356 FieldPosition fp = new FieldPosition(0); 357 logln("d = " + d); 358 logln("BigDecimal.toString(): " + bd.toString()); 359 df.format(d, sb, fp); 360 if (!sb.toString().equals("10000000.0000000100")) { 361 errln("DecimalFormat.format(): " + sb.toString()); 362 } 363 } 364 365 /** 366 * DecimalFormat.format() loses precision 367 */ 368 @Test 369 public void Test4090504 () 370 { 371 double d = 1; 372 logln("d = " + d); 373 DecimalFormat df = new DecimalFormat(); 374 StringBuffer sb; 375 FieldPosition fp; 376 try { 377 for (int i = 17; i <= 20; i++) { 378 df.setMaximumFractionDigits(i); 379 sb = new StringBuffer(""); 380 fp = new FieldPosition(0); 381 logln(" getMaximumFractionDigits() = " + i); 382 logln(" formated: " + df.format(d, sb, fp)); 383 } 384 } catch (Exception foo) { 385 errln("Bug 4090504 regression test failed. Message : " + foo.getMessage()); 386 } 387 } 388 /** 389 * DecimalFormat.parse(String str, ParsePosition pp) loses precision 390 */ 391 @Test 392 public void Test4095713 () 393 { 394 DecimalFormat df = new DecimalFormat(); 395 String str = "0.1234"; 396 Double d1 = new Double(str); 397 Number d2 = df.parse(str, new ParsePosition(0)); 398 logln(d1.toString()); 399 if (d2.doubleValue() != d1.doubleValue()) 400 errln("Bug 4095713 test failed, new double value : " + d2.doubleValue()); 401 } 402 403 /** 404 * DecimalFormat.parse() fails when multiplier is not set to 1 405 */ 406 @Test 407 public void Test4092561 () 408 { 409 Locale savedLocale = Locale.getDefault(); 410 Locale.setDefault(Locale.US); 411 DecimalFormat df = new DecimalFormat(); 412 String str = Long.toString(Long.MIN_VALUE); 413 logln("Long.MIN_VALUE : " + df.parse(str, new ParsePosition(0)).toString()); 414 df.setMultiplier(100); 415 Number num = df.parse(str, new ParsePosition(0)); 416 if (num.doubleValue() != -9.223372036854776E16) { 417 errln("Bug 4092561 test failed when multiplier is set to not 1."); 418 } 419 Locale.setDefault(savedLocale); 420 } 421 422 /** 423 * DecimalFormat: Negative format ignored. 424 */ 425 @Test 426 public void Test4092480 () 427 { 428 DecimalFormat dfFoo = new DecimalFormat("000"); 429 430 try { 431 dfFoo.applyPattern("0000;-000"); 432 if (!dfFoo.toPattern().equals("0000")) 433 errln("dfFoo.toPattern : " + dfFoo.toPattern()); 434 logln(dfFoo.format(42)); 435 logln(dfFoo.format(-42)); 436 dfFoo.applyPattern("000;-000"); 437 if (!dfFoo.toPattern().equals("000")) 438 errln("dfFoo.toPattern : " + dfFoo.toPattern()); 439 logln(dfFoo.format(42)); 440 logln(dfFoo.format(-42)); 441 442 dfFoo.applyPattern("000;-0000"); 443 if (!dfFoo.toPattern().equals("000")) 444 errln("dfFoo.toPattern : " + dfFoo.toPattern()); 445 logln(dfFoo.format(42)); 446 logln(dfFoo.format(-42)); 447 448 dfFoo.applyPattern("0000;-000"); 449 if (!dfFoo.toPattern().equals("0000")) 450 errln("dfFoo.toPattern : " + dfFoo.toPattern()); 451 logln(dfFoo.format(42)); 452 logln(dfFoo.format(-42)); 453 } catch (Exception foo) { 454 errln("Message " + foo.getMessage()); 455 } 456 } 457 /** 458 * NumberFormat.getCurrencyInstance() produces format that uses 459 * decimal separator instead of monetary decimal separator. 460 * 461 * Rewrote this test not to depend on the actual pattern. Pattern should 462 * never contain the monetary separator! Decimal separator in pattern is 463 * interpreted as monetary separator if currency symbol is seen! 464 */ 465 @Test 466 public void Test4087244 () { 467 Locale de = new Locale("pt", "PT"); 468 DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(de); 469 DecimalFormatSymbols sym = df.getDecimalFormatSymbols(); 470 sym.setMonetaryDecimalSeparator('$'); 471 df.setDecimalFormatSymbols(sym); 472 char decSep = sym.getDecimalSeparator(); 473 char monSep = sym.getMonetaryDecimalSeparator(); 474 //char zero = sym.getZeroDigit(); //The variable is never used 475 if (decSep == monSep) { 476 errln("ERROR in test: want decimal sep != monetary sep"); 477 } else { 478 df.setMinimumIntegerDigits(1); 479 df.setMinimumFractionDigits(2); 480 String str = df.format(1.23); 481 String monStr = "1" + monSep + "23"; 482 String decStr = "1" + decSep + "23"; 483 if (str.indexOf(monStr) >= 0 && str.indexOf(decStr) < 0) { 484 logln("OK: 1.23 -> \"" + str + "\" contains \"" + 485 monStr + "\" and not \"" + decStr + '"'); 486 } else { 487 errln("FAIL: 1.23 -> \"" + str + "\", should contain \"" + 488 monStr + 489 "\" and not \"" + decStr + '"'); 490 } 491 } 492 } 493 /** 494 * Number format data rounding errors for locale FR 495 */ 496 @Test 497 public void Test4070798 () { 498 NumberFormat formatter; 499 String tempString; 500 /* User error : 501 String expectedDefault = "-5\u00a0789,987"; 502 String expectedCurrency = "5\u00a0789,98\u00a0F"; 503 String expectedPercent = "-578\u00a0998%"; 504 */ 505 String expectedDefault = "-5\u00a0789,988"; 506 String expectedCurrency = "5\u00a0789,99\u00a0" + EURO; // euro 507 String expectedPercent = "-578\u00a0999\u00a0%"; 508 509 formatter = NumberFormat.getNumberInstance(Locale.FRANCE); 510 tempString = formatter.format (-5789.9876); 511 512 if (tempString.equals(expectedDefault)) { 513 logln ("Bug 4070798 default test passed."); 514 } else { 515 errln("Failed:" + 516 " Expected " + expectedDefault + 517 " Received " + tempString ); 518 } 519 520 521 formatter = NumberFormat.getCurrencyInstance(Locale.FRANCE); 522 tempString = formatter.format( 5789.9876 ); 523 524 if (tempString.equals(expectedCurrency) ) { 525 logln ("Bug 4070798 currency test assed."); 526 } else { 527 errln("Failed:" + 528 " Expected " + expectedCurrency + 529 " Received " + tempString ); 530 } 531 532 533 formatter = NumberFormat.getPercentInstance(Locale.FRANCE); 534 tempString = formatter.format (-5789.9876); 535 536 if (tempString.equals(expectedPercent) ) { 537 logln ("Bug 4070798 percentage test passed."); 538 } else { 539 errln("Failed:" + 540 " Expected " + expectedPercent + 541 " Received " + tempString ); 542 } 543 } 544 /** 545 * Data rounding errors for French (Canada) locale 546 */ 547 @Test 548 public void Test4071005 () { 549 550 NumberFormat formatter; 551 String tempString; 552 /* user error : 553 String expectedDefault = "-5 789,987"; 554 String expectedCurrency = "5 789,98\u00a0$"; 555 String expectedPercent = "-578 998%"; 556 */ 557 String expectedDefault = "-5\u00a0789,988"; 558 String expectedCurrency = "5\u00a0789,99\u00a0$"; 559 String expectedPercent = "-578\u00a0999\u00A0%"; 560 561 formatter = NumberFormat.getNumberInstance(Locale.CANADA_FRENCH); 562 tempString = formatter.format (-5789.9876); 563 if (tempString.equals(expectedDefault)) { 564 logln ("Bug 4071005 default test passed."); 565 } else { 566 errln("Failed:" + 567 " Expected " + expectedDefault + 568 " Received " + tempString ); 569 } 570 571 formatter = NumberFormat.getCurrencyInstance(Locale.CANADA_FRENCH); 572 tempString = formatter.format( 5789.9876 ) ; 573 574 if (tempString.equals(expectedCurrency) ) { 575 logln ("Bug 4071005 currency test passed."); 576 } else { 577 errln("Failed:" + 578 " Expected " + expectedCurrency + 579 " Received " + tempString ); 580 } 581 formatter = NumberFormat.getPercentInstance(Locale.CANADA_FRENCH); 582 tempString = formatter.format (-5789.9876); 583 584 if (tempString.equals(expectedPercent) ) { 585 logln ("Bug 4071005 percentage test passed."); 586 } else { 587 errln("Failed:" + 588 " Expected " + expectedPercent + 589 " Received " + tempString ); 590 } 591 } 592 593 /** 594 * Data rounding errors for German (Germany) locale 595 */ 596 @Test 597 public void Test4071014 () { 598 NumberFormat formatter; 599 String tempString; 600 /* user error : 601 String expectedDefault = "-5.789,987"; 602 String expectedCurrency = "5.789,98\u00a0DM"; 603 String expectedPercent = "-578.998%"; 604 */ 605 String expectedDefault = "-5.789,988"; 606 String expectedCurrency = "5.789,99\u00a0" + EURO; 607 String expectedPercent = "-578.999\u00a0%"; 608 609 formatter = NumberFormat.getNumberInstance(Locale.GERMANY); 610 tempString = formatter.format (-5789.9876); 611 612 if (tempString.equals(expectedDefault)) { 613 logln ("Bug 4071014 default test passed."); 614 } else { 615 errln("Failed:" + 616 " Expected " + expectedDefault + 617 " Received " + tempString ); 618 } 619 620 formatter = NumberFormat.getCurrencyInstance(Locale.GERMANY); 621 tempString = formatter.format( 5789.9876 ) ; 622 623 if (tempString.equals(expectedCurrency) ) { 624 logln ("Bug 4071014 currency test passed."); 625 } else { 626 errln("Failed:" + 627 " Expected " + expectedCurrency + 628 " Received " + tempString ); 629 } 630 631 formatter = NumberFormat.getPercentInstance(Locale.GERMANY); 632 tempString = formatter.format (-5789.9876); 633 634 if (tempString.equals(expectedPercent) ) { 635 logln ("Bug 4071014 percentage test passed."); 636 } else { 637 errln("Failed:" + 638 " Expected " + expectedPercent + 639 " Received " + tempString ); 640 } 641 642 } 643 /** 644 * Data rounding errors for Italian locale number formats 645 * Note- with the Euro, there is no need for currency rounding anymore 646 */ 647 @Test 648 public void Test4071859 () { 649 NumberFormat formatter; 650 String tempString; 651 /* user error : 652 String expectedDefault = "-5.789,987"; 653 String expectedCurrency = "-L.\u00a05.789,98"; 654 String expectedPercent = "-578.998%"; 655 */ 656 String expectedDefault = "-5.789,988"; 657 String expectedCurrency = "-5.789,99\u00A0" + EURO; 658 String expectedPercent = "-578.999%"; 659 660 formatter = NumberFormat.getNumberInstance(Locale.ITALY); 661 tempString = formatter.format (-5789.9876); 662 663 if (tempString.equals(expectedDefault)) { 664 logln ("Bug 4071859 default test passed."); 665 } else { 666 errln("a) Failed:" + 667 " Expected " + expectedDefault + 668 " Received " + tempString ); 669 } 670 671 formatter = NumberFormat.getCurrencyInstance(Locale.ITALY); 672 tempString = formatter.format( -5789.9876 ) ; 673 674 if (tempString.equals(expectedCurrency) ) { 675 logln ("Bug 4071859 currency test passed."); 676 } else { 677 errln("b) Failed:" + 678 " Expected " + expectedCurrency + 679 " Received " + tempString ); 680 } 681 682 formatter = NumberFormat.getPercentInstance(Locale.ITALY); 683 tempString = formatter.format (-5789.9876); 684 685 if (tempString.equals(expectedPercent) ) { 686 logln ("Bug 4071859 percentage test passed."); 687 } else { 688 errln("c) Failed:" + 689 " Expected " + expectedPercent + 690 " Received " + tempString ); 691 } 692 693 } 694 /* bug 4071859 695 * Test rounding for nearest even. 696 */ 697 @Test 698 public void Test4093610() 699 { 700 DecimalFormat df = new DecimalFormat("#0.#"); 701 roundingTest(df, 12.35, "12.4"); 702 roundingTest(df, 12.45, "12.4"); 703 roundingTest(df, 12.452,"12.5"); 704 roundingTest(df, 12.55, "12.6"); 705 roundingTest(df, 12.65, "12.6"); 706 roundingTest(df, 12.652,"12.7"); 707 roundingTest(df, 12.75, "12.8"); 708 roundingTest(df, 12.752,"12.8"); 709 roundingTest(df, 12.85, "12.8"); 710 roundingTest(df, 12.852,"12.9"); 711 roundingTest(df, 12.95, "13"); 712 roundingTest(df, 12.952,"13"); 713 714 } 715 void roundingTest(DecimalFormat df, double x, String expected) 716 { 717 String out = df.format(x); 718 logln("" + x + " formats with 1 fractional digits to " + out); 719 if (!out.equals(expected)) errln("FAIL: Expected " + expected); 720 } 721 /** 722 * Tests the setMaximumFractionDigits limit. 723 */ 724 @Test 725 public void Test4098741() 726 { 727 try { 728 NumberFormat fmt = NumberFormat.getPercentInstance(); 729 fmt.setMaximumFractionDigits(20); 730 logln(fmt.format(.001)); 731 } catch (Exception foo) { 732 warnln("Bug 4098471 failed with exception thrown : " + foo.getMessage()); 733 } 734 } 735 /** 736 * Tests illegal pattern exception. 737 * Fix comment : HShih A31 Part1 will not be fixed and javadoc needs to be updated. 738 * Part2 has been fixed. 739 */ 740 @Test 741 public void Test4074454() 742 { 743 try { 744 DecimalFormat fmt = new DecimalFormat("#,#00.00;-#.#"); 745 logln("format 3456.78: " + fmt.format(3456.78)); //fix "The variable 'fmt' is never used" 746 logln("Inconsistent negative pattern is fine."); 747 DecimalFormat newFmt = new DecimalFormat("#,#00.00 p''ieces;-#,#00.00 p''ieces"); 748 String tempString = newFmt.format(3456.78); 749 if (!tempString.equals("3,456.78 p'ieces")) 750 errln("Failed! 3456.78 p'ieces expected, but got : " + tempString); 751 } catch (Exception foo) { 752 warnln("An exception was thrown for any inconsistent negative pattern."); 753 } 754 } 755 /** 756 * Tests all different comments. 757 * Response to some comments : 758 * [1] DecimalFormat.parse API documentation is more than just one line. 759 * This is not a reproducable doc error in 116 source code. 760 * [2] See updated javadoc. 761 * [3] Fixed. 762 * [4] NumberFormat.parse(String, ParsePosition) : If parsing fails, 763 * a null object will be returned. The unchanged parse position also 764 * reflects an error. 765 * NumberFormat.parse(String) : If parsing fails, an ParseException 766 * will be thrown. 767 * See updated javadoc for more details. 768 * [5] See updated javadoc. 769 * [6] See updated javadoc. 770 * [7] This is a correct behavior if the DateFormat object is linient. 771 * Otherwise, an IllegalArgumentException will be thrown when formatting 772 * "January 35". See GregorianCalendar class javadoc for more details. 773 */ 774 @Test 775 public void Test4099404() 776 { 777 try { 778 DecimalFormat fmt = new DecimalFormat("000.0#0"); 779 logln("format 3456.78: " + fmt.format(3456.78)); //fix "The variable 'fmt' is never used" 780 errln("Bug 4099404 failed applying illegal pattern \"000.0#0\""); 781 } catch (Exception foo) { 782 logln("Bug 4099404 pattern \"000.0#0\" passed"); 783 } 784 try { 785 DecimalFormat fmt = new DecimalFormat("0#0.000"); 786 logln("format 3456.78: " + fmt.format(3456.78)); //fix "The variable 'fmt' is never used" 787 errln("Bug 4099404 failed applying illegal pattern \"0#0.000\""); 788 } catch (Exception foo) { 789 logln("Bug 4099404 pattern \"0#0.000\" passed"); 790 } 791 } 792 /** 793 * DecimalFormat.applyPattern doesn't set minimum integer digits 794 */ 795 @Test 796 public void Test4101481() 797 { 798 DecimalFormat sdf = new DecimalFormat("#,##0"); 799 if (sdf.getMinimumIntegerDigits() != 1) 800 errln("Minimum integer digits : " + sdf.getMinimumIntegerDigits()); 801 } 802 /** 803 * Tests ParsePosition.setErrorPosition() and ParsePosition.getErrorPosition(). 804 */ 805 @Test 806 public void Test4052223() 807 { 808 try { 809 DecimalFormat fmt = new DecimalFormat("#,#00.00"); 810 Number num = fmt.parse("abc3"); 811 errln("Bug 4052223 failed : can't parse string \"a\". Got " + num); 812 } catch (ParseException foo) { 813 logln("Caught expected ParseException : " + foo.getMessage() + " at index : " + foo.getErrorOffset()); 814 } 815 } 816 /** 817 * API tests for API addition request A9. 818 */ 819 @Test 820 public void Test4061302() 821 { 822 DecimalFormatSymbols fmt = new DecimalFormatSymbols(); 823 String currency = fmt.getCurrencySymbol(); 824 String intlCurrency = fmt.getInternationalCurrencySymbol(); 825 char monDecSeparator = fmt.getMonetaryDecimalSeparator(); 826 if (currency.equals("") || 827 intlCurrency.equals("") || 828 monDecSeparator == 0) { 829 errln("getCurrencySymbols failed, got empty string."); 830 } 831 logln("Before set ==> Currency : " + currency + " Intl Currency : " + intlCurrency + " Monetary Decimal Separator : " + monDecSeparator); 832 fmt.setCurrencySymbol("XYZ"); 833 fmt.setInternationalCurrencySymbol("ABC"); 834 fmt.setMonetaryDecimalSeparator('*'); 835 currency = fmt.getCurrencySymbol(); 836 intlCurrency = fmt.getInternationalCurrencySymbol(); 837 monDecSeparator = fmt.getMonetaryDecimalSeparator(); 838 if (!currency.equals("XYZ") || 839 !intlCurrency.equals("ABC") || 840 monDecSeparator != '*') { 841 errln("setCurrencySymbols failed."); 842 } 843 logln("After set ==> Currency : " + currency + " Intl Currency : " + intlCurrency + " Monetary Decimal Separator : " + monDecSeparator); 844 } 845 /** 846 * API tests for API addition request A23. FieldPosition.getBeginIndex and 847 * FieldPosition.getEndIndex. 848 */ 849 @Test 850 public void Test4062486() 851 { 852 DecimalFormat fmt = new DecimalFormat("#,##0.00"); 853 StringBuffer formatted = new StringBuffer(); 854 FieldPosition field = new FieldPosition(0); 855 Double num = new Double(1234.5); 856 fmt.format(num, formatted, field); 857 if (field.getBeginIndex() != 0 && field.getEndIndex() != 5) 858 errln("Format 1234.5 failed. Begin index: " + field.getBeginIndex() + " End index: " + field.getEndIndex()); 859 field.setBeginIndex(7); 860 field.setEndIndex(4); 861 if (field.getBeginIndex() != 7 && field.getEndIndex() != 4) 862 errln("Set begin/end field indexes failed. Begin index: " + field.getBeginIndex() + " End index: " + field.getEndIndex()); 863 } 864 865 /** 866 * DecimalFormat.parse incorrectly works with a group separator. 867 */ 868 @Test 869 public void Test4108738() 870 { 871 872 DecimalFormat df = new DecimalFormat("#,##0.###", new 873 DecimalFormatSymbols(java.util.Locale.US)); 874 String text = "1.222,111"; 875 Number num = df.parse(text,new ParsePosition(0)); 876 if (!num.toString().equals("1.222")) 877 errln("\"" + text + "\" is parsed as " + num); 878 text = "1.222x111"; 879 num = df.parse(text,new ParsePosition(0)); 880 if (!num.toString().equals("1.222")) 881 errln("\"" + text + "\" is parsed as " + num); 882 } 883 884 /** 885 * DecimalFormat.format() incorrectly formats negative doubles. 886 */ 887 @Test 888 public void Test4106658() 889 { 890 Locale savedLocale = Locale.getDefault(); 891 Locale.setDefault(Locale.US); 892 DecimalFormat df = new DecimalFormat(); // Corrected; see 4147706 893 double d1 = -0.0; 894 double d2 = -0.0001; 895 StringBuffer buffer = new StringBuffer(); 896 logln("pattern: \"" + df.toPattern() + "\""); 897 df.format(d1, buffer, new FieldPosition(0)); 898 if (!buffer.toString().equals("-0")) { // Corrected; see 4147706 899 errln(d1 + " is formatted as " + buffer); 900 } 901 buffer.setLength(0); 902 df.format(d2, buffer, new FieldPosition(0)); 903 if (!buffer.toString().equals("-0")) { // Corrected; see 4147706 904 errln(d2 + " is formatted as " + buffer); 905 } 906 Locale.setDefault(savedLocale); 907 } 908 909 /** 910 * DecimalFormat.parse returns 0 if string parameter is incorrect. 911 */ 912 @Test 913 public void Test4106662() 914 { 915 DecimalFormat df = new DecimalFormat(); 916 String text = "x"; 917 ParsePosition pos1 = new ParsePosition(0), pos2 = new ParsePosition(0); 918 919 logln("pattern: \"" + df.toPattern() + "\""); 920 Number num = df.parse(text, pos1); 921 if (num != null) { 922 errln("Test Failed: \"" + text + "\" is parsed as " + num); 923 } 924 df = null; 925 df = new DecimalFormat("$###.00"); 926 num = df.parse("$", pos2); 927 if (num != null){ 928 errln("Test Failed: \"$\" is parsed as " + num); 929 } 930 } 931 932 /** 933 * NumberFormat.parse doesn't return null 934 */ 935 @Test 936 public void Test4114639() 937 { 938 NumberFormat format = NumberFormat.getInstance(); 939 String text = "time 10:x"; 940 ParsePosition pos = new ParsePosition(8); 941 Number result = format.parse(text, pos); 942 if (result != null) errln("Should return null but got : " + result); // Should be null; it isn't 943 } 944 945 /** 946 * DecimalFormat.format(long n) fails if n * multiplier > MAX_LONG. 947 */ 948 @Test 949 public void Test4106664() 950 { 951 DecimalFormat df = new DecimalFormat(); 952 long n = 1234567890123456L; 953 int m = 12345678; 954 BigInteger bigN = BigInteger.valueOf(n); 955 bigN = bigN.multiply(BigInteger.valueOf(m)); 956 df.setMultiplier(m); 957 df.setGroupingUsed(false); 958 logln("formated: " + 959 df.format(n, new StringBuffer(), new FieldPosition(0))); 960 logln("expected: " + bigN.toString()); 961 } 962 /** 963 * DecimalFormat.format incorrectly formats -0.0. 964 */ 965 @Test 966 public void Test4106667() 967 { 968 Locale savedLocale = Locale.getDefault(); 969 Locale.setDefault(Locale.US); 970 DecimalFormat df = new DecimalFormat(); 971 df.setPositivePrefix("+"); 972 df.setNegativePrefix("-"); 973 double d = -0.0; 974 logln("pattern: \"" + df.toPattern() + "\""); 975 StringBuffer buffer = new StringBuffer(); 976 df.format(d, buffer, new FieldPosition(0)); 977 if (!buffer.toString().equals("-0")) { // Corrected; see 4147706 978 errln(d + " is formatted as " + buffer); 979 } 980 Locale.setDefault(savedLocale); 981 } 982 983 /** 984 * DecimalFormat.setMaximumIntegerDigits() works incorrectly. 985 */ 986 @Test 987 public void Test4110936() 988 { 989 // NOTE: Starting in ICU 60, the maximum integer digits is fixed at 100 990 NumberFormat nf = NumberFormat.getInstance(); 991 nf.setMaximumIntegerDigits(99); 992 logln("setMaximumIntegerDigits(99)"); 993 if (nf.getMaximumIntegerDigits() != 99) 994 errln("getMaximumIntegerDigits() returns " + 995 nf.getMaximumIntegerDigits()); 996 } 997 998 /** 999 * Locale data should use generic currency symbol 1000 * 1001 * 1) Make sure that all currency formats use the generic currency symbol. 1002 * 2) Make sure we get the same results using the generic symbol or a 1003 * hard-coded one. 1004 */ 1005 @Test 1006 public void Test4122840() 1007 { 1008 Locale[] locales = NumberFormat.getAvailableLocales(); 1009 1010 outer: 1011 for (int i = 0; i < locales.length; i++) { 1012 ICUResourceBundle rb = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME,locales[i]); 1013 1014 // 1015 // Get the currency pattern for this locale. We have to fish it 1016 // out of the ResourceBundle directly, since DecimalFormat.toPattern 1017 // will return the localized symbol, not \00a4 1018 // 1019 String pattern = rb.getStringWithFallback("NumberElements/latn/patterns/currencyFormat"); 1020 if (pattern.indexOf('\u00A4') == -1 ) { // 'x' not "x" -- workaround bug in IBM JDK 1.4.1 1021 errln("Currency format for " + locales[i] + 1022 " does not contain generic currency symbol:" + 1023 pattern ); 1024 } 1025 1026 // Create a DecimalFormat using the pattern we got and format a number 1027 DecimalFormatSymbols symbols = new DecimalFormatSymbols(locales[i]); 1028 DecimalFormat fmt1 = new DecimalFormat(pattern, symbols); 1029 1030 String result1 = fmt1.format(1.111); 1031 1032 // 1033 // Now substitute in the locale's currency symbol and create another 1034 // pattern. Replace the decimal separator with the monetary separator. 1035 // 1036 //char decSep = symbols.getDecimalSeparator(); //The variable is never used 1037 char monSep = symbols.getMonetaryDecimalSeparator(); 1038 StringBuffer buf = new StringBuffer(pattern); 1039 for (int j = 0; j < buf.length(); j++) { 1040 if (buf.charAt(j) == '\u00a4') { 1041 String cur = "'" + symbols.getCurrencySymbol() + "'"; 1042 buf.replace(j, j+1, cur); 1043 j += cur.length() - 1; 1044 } 1045 } 1046 symbols.setDecimalSeparator(monSep); 1047 DecimalFormat fmt2 = new DecimalFormat(buf.toString(), symbols); 1048 1049 // Actual width of decimal fractions and rounding option are inherited 1050 // from the currency, not the pattern itself. So we need to force 1051 // maximum/minimumFractionDigits and rounding option for the second 1052 // DecimalForamt instance. The fix for ticket#7282 requires this test 1053 // code change to make it work properly. 1054 if (symbols.getCurrency() != null) { 1055 fmt2.setMaximumFractionDigits(symbols.getCurrency().getDefaultFractionDigits()); 1056 fmt2.setMinimumFractionDigits(symbols.getCurrency().getDefaultFractionDigits()); 1057 fmt2.setRoundingIncrement(symbols.getCurrency().getRoundingIncrement()); 1058 } else { 1059 fmt2.setMaximumFractionDigits(fmt1.getMinimumFractionDigits()); 1060 fmt2.setMinimumFractionDigits(fmt1.getMaximumFractionDigits()); 1061 fmt2.setRoundingIncrement(fmt1.getRoundingIncrement()); 1062 } 1063 1064 String result2 = fmt2.format(1.111); 1065 1066 // Currency spacing may have been added by the real DecimalFormat. Account for that here. 1067 if (!result1.equals(result2)) { 1068 if (result1.length() == result2.length() + 1) { 1069 inner: 1070 for (int k=0; k<result2.length(); k++) { 1071 if (result1.charAt(k) != result2.charAt(k)) { 1072 if (result1.charAt(k) == '\u00A0') { 1073 continue outer; // currency spacing OK 1074 } 1075 break inner; 1076 } 1077 } 1078 } 1079 errln("Results for " + locales[i] + " differ: " + result1 + " vs " + result2); 1080 } 1081 } 1082 } 1083 1084 /** 1085 * DecimalFormat.format() delivers wrong string. 1086 */ 1087 @Test 1088 public void Test4125885() 1089 { 1090 double rate = 12.34; 1091 DecimalFormat formatDec = new DecimalFormat ("000.00"); 1092 logln("toPattern: " + formatDec.toPattern()); 1093 String rateString= formatDec.format(rate); 1094 if (!rateString.equals("012.34")) 1095 errln("result : " + rateString + " expected : 012.34"); 1096 rate = 0.1234; 1097 formatDec = null; 1098 formatDec = new DecimalFormat ("+000.00%;-000.00%"); 1099 logln("toPattern: " + formatDec.toPattern()); 1100 rateString= formatDec.format(rate); 1101 if (!rateString.equals("+012.34%")) 1102 errln("result : " + rateString + " expected : +012.34%"); 1103 } 1104 1105 /** 1106 ** 1107 * DecimalFormat produces extra zeros when formatting numbers. 1108 */ 1109 @Test 1110 public void Test4134034() { 1111 DecimalFormat nf = new DecimalFormat("##,###,###.00"); 1112 1113 String f = nf.format(9.02); 1114 if (f.equals("9.02")) logln(f + " ok"); else errln("9.02 -> " + f + "; want 9.02"); 1115 1116 f = nf.format(0); 1117 if (f.equals(".00")) logln(f + " ok"); else errln("0 -> " + f + "; want .00"); 1118 } 1119 1120 /** 1121 * CANNOT REPRODUCE - This bug could not be reproduced. It may be 1122 * a duplicate of 4134034. 1123 * 1124 * JDK 1.1.6 Bug, did NOT occur in 1.1.5 1125 * Possibly related to bug 4125885. 1126 * 1127 * This class demonstrates a regression in version 1.1.6 1128 * of DecimalFormat class. 1129 * 1130 * 1.1.6 Results 1131 * Value 1.2 Format #.00 Result '01.20' !!!wrong 1132 * Value 1.2 Format 0.00 Result '001.20' !!!wrong 1133 * Value 1.2 Format 00.00 Result '0001.20' !!!wrong 1134 * Value 1.2 Format #0.0# Result '1.2' 1135 * Value 1.2 Format #0.00 Result '001.20' !!!wrong 1136 * 1137 * 1.1.5 Results 1138 * Value 1.2 Format #.00 Result '1.20' 1139 * Value 1.2 Format 0.00 Result '1.20' 1140 * Value 1.2 Format 00.00 Result '01.20' 1141 * Value 1.2 Format #0.0# Result '1.2' 1142 * Value 1.2 Format #0.00 Result '1.20' 1143 */ 1144 @Test 1145 public void Test4134300() { 1146 String[] DATA = { 1147 // Pattern Expected string 1148 "#.00", "1.20", 1149 "0.00", "1.20", 1150 "00.00", "01.20", 1151 "#0.0#", "1.2", 1152 "#0.00", "1.20", 1153 }; 1154 for (int i=0; i<DATA.length; i+=2) { 1155 String result = new DecimalFormat(DATA[i]).format(1.2); 1156 if (!result.equals(DATA[i+1])) { 1157 errln("Fail: 1.2 x " + DATA[i] + " = " + result + 1158 "; want " + DATA[i+1]); 1159 } 1160 else { 1161 logln("Ok: 1.2 x " + DATA[i] + " = " + result); 1162 } 1163 } 1164 } 1165 1166 /** 1167 * Empty pattern produces double negative prefix. 1168 */ 1169 @Test 1170 public void Test4140009() { 1171 final double IN[] = { 123.456, -123.456 }; 1172 final String OUT[] = { "123.456", "-123.456" }; 1173 for (int i=0; i<2; ++i) { 1174 DecimalFormat f = null; 1175 switch (i) { 1176 case 0: 1177 f = new DecimalFormat("", 1178 new DecimalFormatSymbols(Locale.ENGLISH)); 1179 break; 1180 case 1: 1181 f = new DecimalFormat("#.#", 1182 new DecimalFormatSymbols(Locale.ENGLISH)); 1183 f.applyPattern(""); 1184 break; 1185 } 1186 for (int j=0; j<2; ++j) { 1187 assertEquals("<empty pat " + i + ">.format(" + IN[j] + ")", 1188 OUT[j], f.format(IN[j])); 1189 } 1190 } 1191 } 1192 1193 /** 1194 * BigDecimal numbers get their fractions truncated by NumberFormat. 1195 */ 1196 @Test 1197 public void Test4141750() { 1198 try { 1199 String str = "12345.67"; 1200 java.math.BigDecimal bd = new java.math.BigDecimal(str); 1201 String sd = NumberFormat.getInstance(Locale.US).format(bd); 1202 if (!sd.endsWith("67")) errln("Fail: " + str + " x format -> " + sd); 1203 } 1204 catch (Exception e) { 1205 warnln(e.toString()); 1206 //e.printStackTrace(); 1207 } 1208 } 1209 1210 /** 1211 * DecimalFormat toPattern() doesn't quote special characters or handle 1212 * single quotes. 1213 */ 1214 @Test 1215 public void Test4145457() { 1216 try { 1217 DecimalFormat nf = (DecimalFormat)NumberFormat.getInstance(); 1218 DecimalFormatSymbols sym = nf.getDecimalFormatSymbols(); 1219 sym.setDecimalSeparator('\''); 1220 nf.setDecimalFormatSymbols(sym); 1221 double pi = 3.14159; 1222 1223 String[] PATS = { "#.00 'num''ber'", "''#.00''" }; 1224 1225 for (int i=0; i<PATS.length; ++i) { 1226 nf.applyPattern(PATS[i]); 1227 String out = nf.format(pi); 1228 String pat = nf.toPattern(); 1229 double val = nf.parse(out).doubleValue(); 1230 1231 nf.applyPattern(pat); 1232 String out2 = nf.format(pi); 1233 String pat2 = nf.toPattern(); 1234 double val2 = nf.parse(out2).doubleValue(); 1235 1236 if (!pat.equals(pat2)) 1237 errln("Fail with \"" + PATS[i] + "\": Patterns should concur, \"" + 1238 pat + "\" vs. \"" + pat2 + "\""); 1239 else 1240 logln("Ok \"" + PATS[i] + "\" toPattern() -> \"" + pat + '"'); 1241 1242 if (val == val2 && out.equals(out2)) { 1243 logln("Ok " + pi + " x \"" + PATS[i] + "\" -> \"" + 1244 out + "\" -> " + val + " -> \"" + 1245 out2 + "\" -> " + val2); 1246 } 1247 else { 1248 errln("Fail " + pi + " x \"" + PATS[i] + "\" -> \"" + 1249 out + "\" -> " + val + " -> \"" + 1250 out2 + "\" -> " + val2); 1251 } 1252 } 1253 } 1254 catch (ParseException e) { 1255 errln("Fail: " + e); 1256 e.printStackTrace(); 1257 } 1258 } 1259 1260 /** 1261 * DecimalFormat.applyPattern() sets minimum integer digits incorrectly. 1262 * CANNOT REPRODUCE 1263 * This bug is a duplicate of 4139344, which is a duplicate of 4134300 1264 */ 1265 @Test 1266 public void Test4147295() { 1267 DecimalFormat sdf = new DecimalFormat(); 1268 String pattern = "#,###"; 1269 logln("Applying pattern \"" + pattern + "\""); 1270 sdf.applyPattern(pattern); 1271 int minIntDig = sdf.getMinimumIntegerDigits(); 1272 // In ICU 58 and older, this case returned 0. 1273 // Now it returns 1 instead, since the pattern parser enforces at least 1 min digit. 1274 if (minIntDig != 1) { 1275 errln("Test failed"); 1276 errln(" Minimum integer digits : " + minIntDig); 1277 errln(" new pattern: " + sdf.toPattern()); 1278 } else { 1279 logln("Test passed"); 1280 logln(" Minimum integer digits : " + minIntDig); 1281 } 1282 } 1283 1284 /** 1285 * DecimalFormat formats -0.0 as +0.0 1286 * See also older related bug 4106658, 4106667 1287 */ 1288 @Test 1289 public void Test4147706() { 1290 DecimalFormat df = new DecimalFormat("#,##0.0##"); 1291 df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH)); 1292 double d1 = -0.0; 1293 double d2 = -0.0001; 1294 StringBuffer f1 = df.format(d1, new StringBuffer(), new FieldPosition(0)); 1295 StringBuffer f2 = df.format(d2, new StringBuffer(), new FieldPosition(0)); 1296 if (!f1.toString().equals("-0.0")) { 1297 errln(d1 + " x \"" + df.toPattern() + "\" is formatted as \"" + f1 + '"'); 1298 } 1299 if (!f2.toString().equals("-0.0")) { 1300 errln(d2 + " x \"" + df.toPattern() + "\" is formatted as \"" + f2 + '"'); 1301 } 1302 } 1303 1304 /** 1305 * NumberFormat cannot format Double.MAX_VALUE 1306 */ 1307 @Test 1308 public void Test4162198() { 1309 double dbl = Double.MAX_VALUE; 1310 NumberFormat f = NumberFormat.getInstance(); 1311 f.setMaximumFractionDigits(Integer.MAX_VALUE); 1312 f.setMaximumIntegerDigits(Integer.MAX_VALUE); 1313 String s = f.format(dbl); 1314 logln("The number " + dbl + " formatted to " + s); 1315 Number n = null; 1316 try { 1317 n = f.parse(s); 1318 } catch (java.text.ParseException e) { 1319 errln("Caught a ParseException:"); 1320 e.printStackTrace(); 1321 } 1322 logln("The string " + s + " parsed as " + n); 1323 assertEquals("Round trip failure", dbl, n.doubleValue()); 1324 } 1325 1326 /** 1327 * NumberFormat does not parse negative zero. 1328 */ 1329 @Test 1330 public void Test4162852() throws ParseException { 1331 for (int i=0; i<2; ++i) { 1332 NumberFormat f = (i == 0) ? NumberFormat.getInstance() 1333 : NumberFormat.getPercentInstance(); 1334 double d = -0.0; 1335 String s = f.format(d); 1336 double e = f.parse(s).doubleValue(); 1337 logln("" + 1338 d + " -> " + 1339 '"' + s + '"' + " -> " + 1340 e); 1341 if (e != 0.0 || 1.0/e > 0.0) { 1342 logln("Failed to parse negative zero"); 1343 } 1344 } 1345 } 1346 1347 /** 1348 * NumberFormat truncates data 1349 */ 1350 @Test 1351 public void Test4167494() throws Exception { 1352 NumberFormat fmt = NumberFormat.getInstance(Locale.US); 1353 1354 double a = Double.MAX_VALUE; 1355 String s = fmt.format(a); 1356 double b = fmt.parse(s).doubleValue(); 1357 boolean match = a == b; 1358 if (match) { 1359 logln("" + a + " -> \"" + s + "\" -> " + b + " ok"); 1360 } else { 1361 errln("" + a + " -> \"" + s + "\" -> " + b + " FAIL"); 1362 } 1363 1364 // We don't test Double.MIN_VALUE because the locale data for the US 1365 // currently doesn't specify enough digits to display Double.MIN_VALUE. 1366 // This is correct for now; however, we leave this here as a reminder 1367 // in case we want to address this later. 1368 if (false) { 1369 a = Double.MIN_VALUE; 1370 s = fmt.format(a); 1371 b = fmt.parse(s).doubleValue(); 1372 match = a == b; 1373 if (match) { 1374 logln("" + a + " -> \"" + s + "\" -> " + b + " ok"); 1375 } else { 1376 errln("" + a + " -> \"" + s + "\" -> " + b + " FAIL"); 1377 } 1378 } 1379 } 1380 1381 /** 1382 * DecimalFormat.parse() fails when ParseIntegerOnly set to true 1383 */ 1384 @Test 1385 public void Test4170798() { 1386 Locale savedLocale = Locale.getDefault(); 1387 Locale.setDefault(Locale.US); 1388 DecimalFormat df = new DecimalFormat(); 1389 df.setParseIntegerOnly(true); 1390 Number n = df.parse("-0.0", new ParsePosition(0)); 1391 if (!(n instanceof Double) 1392 || n.intValue() != 0) { 1393 errln("FAIL: parse(\"-0.0\") returns " + 1394 n + " (" + n.getClass().getName() + ')'); 1395 } 1396 Locale.setDefault(savedLocale); 1397 } 1398 1399 /** 1400 * toPattern only puts the first grouping separator in. 1401 */ 1402 @Test 1403 public void Test4176114() { 1404 String[] DATA = { 1405 "00", "00", 1406 "000", "000", // No grouping 1407 "#000", "000", // No grouping 1408 "#,##0", "#,##0", 1409 "#,000", "#,000", 1410 "0,000", "0,000", 1411 "00,000", "00,000", 1412 "000,000", "000,000", 1413 "0,000,000,000,000.0000", "0,000,000,000,000.0000", // Reported 1414 }; 1415 for (int i=0; i<DATA.length; i+=2) { 1416 DecimalFormat df = new DecimalFormat(DATA[i]); 1417 String s = df.toPattern(); 1418 if (!s.equals(DATA[i+1])) { 1419 errln("FAIL: " + DATA[i] + " -> " + s + ", want " + DATA[i+1]); 1420 } 1421 } 1422 } 1423 1424 /** 1425 * DecimalFormat is incorrectly rounding numbers like 1.2501 to 1.2 1426 */ 1427 @Test 1428 public void Test4179818() { 1429 String DATA[] = { 1430 // Input Pattern Expected output 1431 "1.2511", "#.#", "1.3", 1432 "1.2501", "#.#", "1.3", 1433 "0.9999", "#", "1", 1434 }; 1435 DecimalFormat fmt = new DecimalFormat("#", 1436 new DecimalFormatSymbols(Locale.US)); 1437 for (int i=0; i<DATA.length; i+=3) { 1438 double in = Double.valueOf(DATA[i]).doubleValue(); 1439 String pat = DATA[i+1]; 1440 String exp = DATA[i+2]; 1441 fmt.applyPattern(pat); 1442 String out = fmt.format(in); 1443 if (out.equals(exp)) { 1444 logln("Ok: " + in + " x " + pat + " = " + out); 1445 } else { 1446 errln("FAIL: " + in + " x " + pat + " = " + out + 1447 ", expected " + exp); 1448 } 1449 } 1450 } 1451 1452 /** 1453 * Some DecimalFormatSymbols changes are not picked up by DecimalFormat. 1454 * This includes the minus sign, currency symbol, international currency 1455 * symbol, percent, and permille. This is filed as bugs 4212072 and 1456 * 4212073. 1457 */ 1458 @Test 1459 public void Test4212072() throws IOException, ClassNotFoundException { 1460 DecimalFormatSymbols sym = new DecimalFormatSymbols(Locale.US); 1461 DecimalFormat fmt = new DecimalFormat("#", sym); 1462 1463 sym.setMinusSign('^'); 1464 fmt.setDecimalFormatSymbols(sym); 1465 if (!fmt.format(-1).equals("^1")) { 1466 errln("FAIL: -1 x (minus=^) -> " + fmt.format(-1) + 1467 ", exp ^1"); 1468 } 1469 if (!fmt.getNegativePrefix().equals("^")) { 1470 errln("FAIL: (minus=^).getNegativePrefix -> " + 1471 fmt.getNegativePrefix() + ", exp ^"); 1472 } 1473 sym.setMinusSign('-'); 1474 1475 fmt.applyPattern("#%"); 1476 sym.setPercent('^'); 1477 fmt.setDecimalFormatSymbols(sym); 1478 if (!fmt.format(0.25).equals("25^")) { 1479 errln("FAIL: 0.25 x (percent=^) -> " + fmt.format(0.25) + 1480 ", exp 25^"); 1481 } 1482 if (!fmt.getPositiveSuffix().equals("^")) { 1483 errln("FAIL: (percent=^).getPositiveSuffix -> " + 1484 fmt.getPositiveSuffix() + ", exp ^"); 1485 } 1486 sym.setPercent('%'); 1487 1488 fmt.applyPattern("#\u2030"); 1489 sym.setPerMill('^'); 1490 fmt.setDecimalFormatSymbols(sym); 1491 if (!fmt.format(0.25).equals("250^")) { 1492 errln("FAIL: 0.25 x (permill=^) -> " + fmt.format(0.25) + 1493 ", exp 250^"); 1494 } 1495 if (!fmt.getPositiveSuffix().equals("^")) { 1496 errln("FAIL: (permill=^).getPositiveSuffix -> " + 1497 fmt.getPositiveSuffix() + ", exp ^"); 1498 } 1499 sym.setPerMill('\u2030'); 1500 1501 fmt.applyPattern("\u00A4#.00"); 1502 sym.setCurrencySymbol("usd"); 1503 fmt.setDecimalFormatSymbols(sym); 1504 if (!fmt.format(12.5).equals("usd12.50")) { 1505 errln("FAIL: 12.5 x (currency=usd) -> " + fmt.format(12.5) + 1506 ", exp usd12.50"); 1507 } 1508 if (!fmt.getPositivePrefix().equals("usd")) { 1509 errln("FAIL: (currency=usd).getPositivePrefix -> " + 1510 fmt.getPositivePrefix() + ", exp usd"); 1511 } 1512 sym.setCurrencySymbol("$"); 1513 1514 fmt.applyPattern("\u00A4\u00A4#.00"); 1515 sym.setInternationalCurrencySymbol("DOL"); 1516 fmt.setDecimalFormatSymbols(sym); 1517 if (!fmt.format(12.5).equals("DOL12.50")) { 1518 errln("FAIL: 12.5 x (intlcurrency=DOL) -> " + fmt.format(12.5) + 1519 ", exp DOL12.50"); 1520 } 1521 if (!fmt.getPositivePrefix().equals("DOL")) { 1522 errln("FAIL: (intlcurrency=DOL).getPositivePrefix -> " + 1523 fmt.getPositivePrefix() + ", exp DOL"); 1524 } 1525 sym.setInternationalCurrencySymbol("USD"); 1526 1527 if (VersionInfo.ICU_VERSION == VersionInfo.getInstance(2,2)) { 1528 // bug in 2.2 that fails this test 1529 // to be fixed in the later versions 1530 System.out.println("\n Test skipped for release 2.2"); 1531 return; 1532 } 1533 1534 // Since the pattern logic has changed, make sure that patterns round 1535 // trip properly. Test stream in/out integrity too. 1536 Locale[] avail = NumberFormat.getAvailableLocales(); 1537 for (int i=0; i<avail.length; ++i) { 1538 if ((avail[i].getLanguage().equals("ji") || avail[i].getLanguage().equals("bm")) && 1539 logKnownIssue("11234", "Symbol roundtrip issues for locales ji, bm")) { 1540 continue; 1541 } 1542 for (int j=0; j<3; ++j) { 1543 NumberFormat nf; 1544 switch (j) { 1545 case 0: 1546 nf = NumberFormat.getInstance(avail[i]); 1547 break; 1548 case 1: 1549 nf = NumberFormat.getCurrencyInstance(avail[i]); 1550 break; 1551 default: 1552 nf = NumberFormat.getPercentInstance(avail[i]); 1553 break; 1554 } 1555 DecimalFormat df = (DecimalFormat) nf; 1556 1557 // Test toPattern/applyPattern round trip 1558 String pat = df.toPattern(); 1559 DecimalFormatSymbols symb = new DecimalFormatSymbols(avail[i]); 1560 DecimalFormat f2 = new DecimalFormat(pat, symb); 1561 f2.setCurrency(df.getCurrency()); // Currency does not travel with the pattern string 1562 if (!df.equals(f2)) { 1563 errln("FAIL: " + avail[i] + " #" + j + " -> \"" + pat + 1564 "\" -> \"" + f2.toPattern() + '"'); 1565 } 1566 1567 // Test toLocalizedPattern/applyLocalizedPattern round trip 1568 pat = df.toLocalizedPattern(); 1569 try{ 1570 f2.applyLocalizedPattern(pat); 1571 1572 String s1 = f2.format(123456); 1573 String s2 = df.format(123456); 1574 if(!s1.equals(s2)){ 1575 errln("FAIL: " + avail[i] + " #" + j + " -> localized \"" + s2 + 1576 "\" -> \"" + s2 + '"'+ " in locale "+df.getLocale(ULocale.ACTUAL_LOCALE)); 1577 1578 } 1579 1580 // Equality of formatter objects is NOT guaranteed across toLocalizedPattern/applyLocalizedPattern. 1581 // However, equality of relevant properties is guaranteed. 1582 assertEquals("Localized FAIL on posPrefix", df.getPositivePrefix(), f2.getPositivePrefix()); 1583 assertEquals("Localized FAIL on posSuffix", df.getPositiveSuffix(), f2.getPositiveSuffix()); 1584 assertEquals("Localized FAIL on negPrefix", df.getNegativePrefix(), f2.getNegativePrefix()); 1585 assertEquals("Localized FAIL on negSuffix", df.getNegativeSuffix(), f2.getNegativeSuffix()); 1586 assertEquals("Localized FAIL on groupingSize", df.getGroupingSize(), f2.getGroupingSize()); 1587 assertEquals("Localized FAIL on secondaryGroupingSize", df.getSecondaryGroupingSize(), f2.getSecondaryGroupingSize()); 1588 assertEquals("Localized FAIL on minFrac", df.getMinimumFractionDigits(), f2.getMinimumFractionDigits()); 1589 assertEquals("Localized FAIL on maxFrac", df.getMaximumFractionDigits(), f2.getMaximumFractionDigits()); 1590 assertEquals("Localized FAIL on minInt", df.getMinimumIntegerDigits(), f2.getMinimumIntegerDigits()); 1591 assertEquals("Localized FAIL on maxInt", df.getMaximumIntegerDigits(), f2.getMaximumIntegerDigits()); 1592 1593 }catch(IllegalArgumentException ex){ 1594 //throw new AssertionError("For locale " + avail[i], ex); 1595 throw new AssertionError("For locale " + avail[i] + ": " + ex.getMessage()); 1596 } 1597 1598 1599 // Test writeObject/readObject round trip 1600 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 1601 ObjectOutputStream oos = new ObjectOutputStream(baos); 1602 oos.writeObject(df); 1603 oos.flush(); 1604 baos.close(); 1605 byte[] bytes = baos.toByteArray(); 1606 ObjectInputStream ois = 1607 new ObjectInputStream(new ByteArrayInputStream(bytes)); 1608 f2 = (DecimalFormat) ois.readObject(); 1609 if (!df.equals(f2)) { 1610 errln("FAIL: Stream in/out " + avail[i] + " -> \"" + pat + 1611 "\" -> " + 1612 (f2 != null ? ("\""+f2.toPattern()+'"') : "null")); 1613 } 1614 1615 } 1616 } 1617 1618 // @since ICU 2.4 1619 // Make sure that all special characters, when quoted in a suffix or 1620 // prefix, lose their special meaning. 1621 char[] SPECIALS = { '0', ',', '.', '\u2030', '%', '#', 1622 ';', 'E', '*', '+', '-' }; 1623 sym = new DecimalFormatSymbols(Locale.US); 1624 for (int j=0; j<SPECIALS.length; ++j) { 1625 char special = SPECIALS[j]; 1626 String pat = "'" + special + "'0'" + special + "'"; 1627 try { 1628 fmt = new DecimalFormat(pat, sym); 1629 String pat2 = fmt.toPattern(); 1630 if (!pat.equals(pat2)) { 1631 errln("FAIL: Pattern \"" + pat + "\" => toPattern() => \"" + 1632 pat2 + "\""); 1633 } 1634 String s = fmt.format(123); 1635 String exp = "" + special + "123" + special; 1636 if (!s.equals(exp)) { 1637 errln("FAIL: 123 x \"" + pat + "\" => \"" + s + "\", exp \"" + 1638 exp + "\""); 1639 } 1640 } catch (IllegalArgumentException e) { 1641 errln("FAIL: Pattern \"" + pat + "\" => " + e.getMessage()); 1642 } 1643 } 1644 } 1645 1646 /** 1647 * DecimalFormat.parse() fails for mulipliers 2^n. 1648 */ 1649 @Test 1650 public void Test4216742() throws ParseException { 1651 DecimalFormat fmt = (DecimalFormat) NumberFormat.getInstance(Locale.US); 1652 long[] DATA = { Long.MIN_VALUE, Long.MAX_VALUE, -100000000L, 100000000L}; 1653 for (int i=0; i<DATA.length; ++i) { 1654 String str = Long.toString(DATA[i]); 1655 for (int m = 1; m <= 100; m++) { 1656 fmt.setMultiplier(m); 1657 long n = fmt.parse(str).longValue(); 1658 if (n > 0 != DATA[i] > 0) { 1659 errln("\"" + str + "\" parse(x " + fmt.getMultiplier() + 1660 ") => " + n); 1661 } 1662 } 1663 } 1664 } 1665 1666 /** 1667 * DecimalFormat formats 1.001 to "1.00" instead of "1" with 2 fraction 1668 * digits. 1669 */ 1670 @Test 1671 public void Test4217661() { 1672 Object[] DATA = { 1673 new Double(0.001), "0", 1674 new Double(1.001), "1", 1675 new Double(0.006), "0.01", 1676 new Double(1.006), "1.01", 1677 }; 1678 NumberFormat fmt = NumberFormat.getInstance(Locale.US); 1679 fmt.setMaximumFractionDigits(2); 1680 for (int i=0; i<DATA.length; i+=2) { 1681 String s = fmt.format(((Double) DATA[i]).doubleValue()); 1682 if (!s.equals(DATA[i+1])) { 1683 errln("FAIL: Got " + s + ", exp " + DATA[i+1]); 1684 } 1685 } 1686 } 1687 1688 /** 1689 * 4243011: Formatting .5 rounds to "1" instead of "0" 1690 */ 1691 @Test 1692 public void Test4243011() { 1693 double DATA[] = {0.5, 1.5, 2.5, 3.5, 4.5}; 1694 String EXPECTED[] = {"0.", "2.", "2.", "4.", "4."}; 1695 1696 DecimalFormat format = new DecimalFormat("0."); 1697 for (int i = 0; i < DATA.length; i++) { 1698 String result = format.format(DATA[i]); 1699 if (result.equals(EXPECTED[i])) { 1700 logln("OK: got " + result); 1701 } else { 1702 errln("FAIL: got " + result); 1703 } 1704 } 1705 } 1706 1707 /** 1708 * 4243108: format(0.0) gives "0.1" if preceded by parse("99.99") 1709 */ 1710 @Test 1711 public void Test4243108() { 1712 DecimalFormat f = new DecimalFormat("#.#"); 1713 String result = f.format(0.0); 1714 if (result.equals("0")) { 1715 logln("OK: got " + result); 1716 } else { 1717 errln("FAIL: got " + result); 1718 } 1719 try { 1720 double dResult = f.parse("99.99").doubleValue(); 1721 if (dResult == 99.99) { 1722 logln("OK: got " + dResult); 1723 } else { 1724 errln("FAIL: got " + dResult); 1725 } 1726 } catch (ParseException e) { 1727 errln("Caught a ParseException:"); 1728 e.printStackTrace(); 1729 } 1730 result = f.format(0.0); 1731 if (result.equals("0")) { 1732 logln("OK: got " + result); 1733 } else { 1734 errln("FAIL: got " + result); 1735 } 1736 } 1737 1738 /** 1739 * 4330377: DecimalFormat engineering notation gives incorrect results 1740 */ 1741 @Test 1742 public void test4330377() { 1743 /* 1744 double[] input = {5000.0, 500.0, 50.0, 5.0, 0.5, 0.05, 0.005, 0.0005, 1745 5050.0, 505.0, 50.5, 5.05, 0.505, 0.0505, 0.00505, 0.000505}; 1746 String[] pattern = {"000.#E0", "##0.#E0", "#00.#E0"}; 1747 String[][] expected = { 1748 // it's questionable whether "#00.#E0" should result in post-decimal 1749 // zeroes, i.e., whether "5.0E3", "5.0E0", "5.0E-3" are really good 1750 {"500E1", "5E3", "5.0E3"}, 1751 {"500E0", "500E0", "500E0"}, 1752 {"500E-1", "50E0", "50E0"}, 1753 {"500E-2", "5E0", "5.0E0"}, 1754 {"500E-3", "500E-3", "500E-3"}, 1755 {"500E-4", "50E-3", "50E-3"}, 1756 {"500E-5", "5E-3", "5.0E-3"}, 1757 {"500E-6", "500E-6", "500E-6"}, 1758 {"505E1", "5.05E3", "5.05E3"}, 1759 {"505E0", "505E0", "505E0"}, 1760 {"505E-1", "50.5E0", "50.5E0"}, 1761 {"505E-2", "5.05E0", "5.05E0"}, 1762 {"505E-3", "505E-3", "505E-3"}, 1763 {"505E-4", "50.5E-3", "50.5E-3"}, 1764 {"505E-5", "5.05E-3", "5.05E-3"}, 1765 {"505E-6", "505E-6", "505E-6"} 1766 }; 1767 for (int i = 0; i < input.length; i++) { 1768 for (int j = 0; j < pattern.length; j++) { 1769 DecimalFormat format = new DecimalFormat(pattern[j]); 1770 String result = format.format(input[i]); 1771 if (!result.equals(expected[i][j])) { 1772 errln("FAIL: input: " + input[i] + 1773 ", pattern: " + pattern[j] + 1774 ", expected: " + expected[i][j] + 1775 ", got: " + result); 1776 } 1777 } 1778 } 1779 */ 1780 } 1781 1782 /** 1783 * 4233840: NumberFormat does not round correctly 1784 */ 1785 @Test 1786 public void test4233840() { 1787 float f = 0.0099f; 1788 1789 NumberFormat nf = new DecimalFormat("0.##", new DecimalFormatSymbols(Locale.US)); 1790 nf.setMinimumFractionDigits(2); 1791 1792 String result = nf.format(f); 1793 1794 if (!result.equals("0.01")) { 1795 errln("FAIL: input: " + f + ", expected: 0.01, got: " + result); 1796 } 1797 } 1798 1799 /** 1800 * 4241880: Decimal format doesnt round a double properly when the number is less than 1 1801 */ 1802 @Test 1803 public void test4241880() { 1804 Locale savedLocale = Locale.getDefault(); 1805 Locale.setDefault(Locale.US); 1806 double[] input = { 1807 .019, .009, .015, .016, .014, 1808 .004, .005, .006, .007, .008, 1809 .5, 1.5, .05, .15, .005, 1810 .015, .0005, .0015, 1811 }; 1812 String[] pattern = { 1813 "##0%", "##0%", "##0%", "##0%", "##0%", 1814 "##0%", "##0%", "##0%", "##0%", "##0%", 1815 "#,##0", "#,##0", "#,##0.0", "#,##0.0", "#,##0.00", 1816 "#,##0.00", "#,##0.000", "#,##0.000", 1817 }; 1818 String[] expected = { 1819 "2%", "1%", "2%", "2%", "1%", 1820 "0%", "0%", "1%", "1%", "1%", 1821 "0", "2", "0.0", "0.2", "0.00", 1822 "0.02", "0.000", "0.002", 1823 }; 1824 for (int i = 0; i < input.length; i++) { 1825 DecimalFormat format = new DecimalFormat(pattern[i]); 1826 String result = format.format(input[i]); 1827 if (!result.equals(expected[i])) { 1828 errln("FAIL: input: " + input[i] + 1829 ", pattern: " + pattern[i] + 1830 ", expected: " + expected[i] + 1831 ", got: " + result); 1832 } 1833 } 1834 Locale.setDefault(savedLocale); 1835 } 1836 } 1837 1838 class myformat implements Serializable 1839 { 1840 /** 1841 * For serialization 1842 */ 1843 private static final long serialVersionUID = 4120813612616076506L; 1844 DateFormat _dateFormat = DateFormat.getDateInstance(); 1845 1846 public String Now() 1847 { 1848 GregorianCalendar calendar = new GregorianCalendar(); 1849 Date t = calendar.getTime(); 1850 String nowStr = _dateFormat.format(t); 1851 return nowStr; 1852 } 1853 } 1854 1855 class MyNumberFormat extends NumberFormat { 1856 /** 1857 * For serialization 1858 */ 1859 private static final long serialVersionUID = 1251303884737169952L; 1860 @Override 1861 public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { 1862 return new StringBuffer(""); 1863 } 1864 @Override 1865 public StringBuffer format(long number,StringBuffer toAppendTo, FieldPosition pos) { 1866 return new StringBuffer(""); 1867 } 1868 @Override 1869 public Number parse(String text, ParsePosition parsePosition) { 1870 return new Integer(0); 1871 } 1872 @Override 1873 public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) { 1874 return new StringBuffer(""); 1875 } 1876 @Override 1877 public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos) { 1878 return new StringBuffer(""); 1879 } 1880 @Override 1881 public StringBuffer format(android.icu.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) { 1882 return new StringBuffer(""); 1883 } 1884 } 1885 1886