< prev index next >

test/java/text/Format/NumberFormat/BigDecimalFormat.java

Print this page




 776      * specified
 777      */
 778     void test_Format_in_NumberFormat_Long_checkDigits() {
 779         String from, to;
 780 
 781         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 782         if (!(nf instanceof DecimalFormat)) {
 783             throw new RuntimeException("Couldn't get DecimalFormat instance.");
 784         }
 785 
 786         ((DecimalFormat)nf).applyPattern("#,##0.###");
 787         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 0);
 788 
 789         // From: 1234567890
 790         // To:   000,0...0,000,123,456,789
 791         //       -------------
 792         //       300 zeros
 793         formatted.setLength(0);
 794         from = "123456789";
 795         to   = sep_zero.substring(0, 399) + ",123,456,789";
 796         nf.format(new Long(from), formatted, new FieldPosition(0));
 797         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 798 
 799         /* ------------------------------------------------------------------ */
 800 
 801         ((DecimalFormat)nf).applyPattern("##0.###");
 802         ((DecimalFormat)nf).setMultiplier(-1);
 803         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 360);
 804 
 805         // From: 1234567890
 806         // To:   -0000...0000123456789.000...000
 807         //      -------------
 808         //        300 zeros
 809         formatted.setLength(0);
 810         from = "123456789";
 811         to   = "-" + nonsep_zero.substring(0, 300) + "123456789." +
 812                nonsep_zero.substring(0, 340);
 813         nf.format(new Long(from), formatted, new FieldPosition(0));
 814         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 815 
 816         /* ------------------------------------------------------------------ */
 817 
 818         ((DecimalFormat)nf).applyPattern("#,##0.###");
 819         ((DecimalFormat)nf).setMultiplier(Integer.MAX_VALUE);
 820         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 0);
 821 
 822         // From: Long.MAX_VALUE
 823         // To:   000,0...0,000,019,807,040,619,342,712,359,383,728,129
 824         //       ---------------
 825         //       280 zeros
 826         formatted.setLength(0);
 827         from = Long.toString(Long.MAX_VALUE);
 828         to   = sep_zero.substring(0, 373) +
 829                "19,807,040,619,342,712,359,383,728,129";
 830         nf.format(new Long(from), formatted, new FieldPosition(0));
 831         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 832 
 833         /* ------------------------------------------------------------------ */
 834 
 835         ((DecimalFormat)nf).applyPattern("0.###E0");
 836         ((DecimalFormat)nf).setMultiplier(Integer.MIN_VALUE);
 837         setDigits(nf, 1, 1, Integer.MAX_VALUE, 360);
 838 
 839         // From: Long.MAX_VALUE
 840         // To:   -1.9807040628566084396238503936000...000E28
 841         //                                      ---------
 842         //                                      312 zeros
 843         formatted.setLength(0);
 844         from = Long.toString(Long.MAX_VALUE);
 845         to   = "-1.9807040628566084396238503936" +
 846                nonsep_zero.substring(0, 312) + "E28";
 847         nf.format(new Long(from), formatted, new FieldPosition(0));
 848         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 849 
 850         /* ------------------------------------------------------------------ */
 851 
 852         ((DecimalFormat)nf).applyPattern("##0.###E0");
 853         ((DecimalFormat)nf).setMultiplier(Integer.MAX_VALUE);
 854         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 360);
 855 
 856         // From: Long.MIN_VALUE
 857         // To:   -198070406193427123615312117760000...0000.000...000E-280
 858         //                                     ----------- ---------
 859         //                                      280 zeros  340 zeros
 860         formatted.setLength(0);
 861         from = Long.toString(Long.MIN_VALUE);
 862         to   = "-19807040619342712361531211776" +
 863                nonsep_zero.substring(0, 280) + "." +
 864                nonsep_zero.substring(0, 340) + "E-280";
 865         nf.format(new Long(from), formatted, new FieldPosition(0));
 866         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 867 
 868         /* ------------------------------------------------------------------ */
 869 
 870         ((DecimalFormat)nf).applyPattern("#,##0.###");
 871         ((DecimalFormat)nf).setMultiplier(Integer.MIN_VALUE);
 872         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 360);
 873 
 874         // From: Long.MIN_VALUE
 875         // To:   000,0...0,000,019,807,040,628,566,084,398,385,987,584.000...000
 876         //       ---------------                                       ---------
 877         //          280 zeros                                          340 zeros
 878         formatted.setLength(0);
 879         from = Long.toString(Long.MIN_VALUE);
 880         to   = sep_zero.substring(0, 373) +
 881                "19,807,040,628,566,084,398,385,987,584." +
 882                nonsep_zero.substring(0, 340);
 883         nf.format(new Long(from), formatted, new FieldPosition(0));
 884         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 885     }
 886 
 887     /**
 888      * Test for special numbers
 889      *    Double.NaN
 890      *    Double.POSITIVE_INFINITY
 891      *    Double.NEGATIVE_INFINITY
 892      */
 893     void test_Format_in_NumberFormat_SpecialNumber() {
 894         String from, to;
 895 
 896         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 897         if (!(nf instanceof DecimalFormat)) {
 898             throw new RuntimeException("Couldn't get DecimalFormat instance.");
 899         }
 900 
 901         ((DecimalFormat)nf).applyPattern("#,##0.###");
 902         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
 903 




 776      * specified
 777      */
 778     void test_Format_in_NumberFormat_Long_checkDigits() {
 779         String from, to;
 780 
 781         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 782         if (!(nf instanceof DecimalFormat)) {
 783             throw new RuntimeException("Couldn't get DecimalFormat instance.");
 784         }
 785 
 786         ((DecimalFormat)nf).applyPattern("#,##0.###");
 787         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 0);
 788 
 789         // From: 1234567890
 790         // To:   000,0...0,000,123,456,789
 791         //       -------------
 792         //       300 zeros
 793         formatted.setLength(0);
 794         from = "123456789";
 795         to   = sep_zero.substring(0, 399) + ",123,456,789";
 796         nf.format(123456789L, formatted, new FieldPosition(0));
 797         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 798 
 799         /* ------------------------------------------------------------------ */
 800 
 801         ((DecimalFormat)nf).applyPattern("##0.###");
 802         ((DecimalFormat)nf).setMultiplier(-1);
 803         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 360);
 804 
 805         // From: 1234567890
 806         // To:   -0000...0000123456789.000...000
 807         //      -------------
 808         //        300 zeros
 809         formatted.setLength(0);
 810         from = "123456789";
 811         to   = "-" + nonsep_zero.substring(0, 300) + "123456789." +
 812                nonsep_zero.substring(0, 340);
 813         nf.format(123456789L, formatted, new FieldPosition(0));
 814         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 815 
 816         /* ------------------------------------------------------------------ */
 817 
 818         ((DecimalFormat)nf).applyPattern("#,##0.###");
 819         ((DecimalFormat)nf).setMultiplier(Integer.MAX_VALUE);
 820         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 0);
 821 
 822         // From: Long.MAX_VALUE
 823         // To:   000,0...0,000,019,807,040,619,342,712,359,383,728,129
 824         //       ---------------
 825         //       280 zeros
 826         formatted.setLength(0);
 827         from = Long.toString(Long.MAX_VALUE);
 828         to   = sep_zero.substring(0, 373) +
 829                "19,807,040,619,342,712,359,383,728,129";
 830         nf.format(Long.MAX_VALUE, formatted, new FieldPosition(0));
 831         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 832 
 833         /* ------------------------------------------------------------------ */
 834 
 835         ((DecimalFormat)nf).applyPattern("0.###E0");
 836         ((DecimalFormat)nf).setMultiplier(Integer.MIN_VALUE);
 837         setDigits(nf, 1, 1, Integer.MAX_VALUE, 360);
 838 
 839         // From: Long.MAX_VALUE
 840         // To:   -1.9807040628566084396238503936000...000E28
 841         //                                      ---------
 842         //                                      312 zeros
 843         formatted.setLength(0);
 844         from = Long.toString(Long.MAX_VALUE);
 845         to   = "-1.9807040628566084396238503936" +
 846                nonsep_zero.substring(0, 312) + "E28";
 847         nf.format(Long.MAX_VALUE, formatted, new FieldPosition(0));
 848         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 849 
 850         /* ------------------------------------------------------------------ */
 851 
 852         ((DecimalFormat)nf).applyPattern("##0.###E0");
 853         ((DecimalFormat)nf).setMultiplier(Integer.MAX_VALUE);
 854         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 360);
 855 
 856         // From: Long.MIN_VALUE
 857         // To:   -198070406193427123615312117760000...0000.000...000E-280
 858         //                                     ----------- ---------
 859         //                                      280 zeros  340 zeros
 860         formatted.setLength(0);
 861         from = Long.toString(Long.MIN_VALUE);
 862         to   = "-19807040619342712361531211776" +
 863                nonsep_zero.substring(0, 280) + "." +
 864                nonsep_zero.substring(0, 340) + "E-280";
 865         nf.format(Long.MIN_VALUE, formatted, new FieldPosition(0));
 866         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 867 
 868         /* ------------------------------------------------------------------ */
 869 
 870         ((DecimalFormat)nf).applyPattern("#,##0.###");
 871         ((DecimalFormat)nf).setMultiplier(Integer.MIN_VALUE);
 872         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 360);
 873 
 874         // From: Long.MIN_VALUE
 875         // To:   000,0...0,000,019,807,040,628,566,084,398,385,987,584.000...000
 876         //       ---------------                                       ---------
 877         //          280 zeros                                          340 zeros
 878         formatted.setLength(0);
 879         from = Long.toString(Long.MIN_VALUE);
 880         to   = sep_zero.substring(0, 373) +
 881                "19,807,040,628,566,084,398,385,987,584." +
 882                nonsep_zero.substring(0, 340);
 883         nf.format(Long.MIN_VALUE, formatted, new FieldPosition(0));
 884         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 885     }
 886 
 887     /**
 888      * Test for special numbers
 889      *    Double.NaN
 890      *    Double.POSITIVE_INFINITY
 891      *    Double.NEGATIVE_INFINITY
 892      */
 893     void test_Format_in_NumberFormat_SpecialNumber() {
 894         String from, to;
 895 
 896         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 897         if (!(nf instanceof DecimalFormat)) {
 898             throw new RuntimeException("Couldn't get DecimalFormat instance.");
 899         }
 900 
 901         ((DecimalFormat)nf).applyPattern("#,##0.###");
 902         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
 903 


< prev index next >