OLD | NEW |
(Empty) | |
| 1 // © 2017 and later: Unicode, Inc. and others. |
| 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
| 3 package com.ibm.icu.impl.number; |
| 4 |
| 5 import java.math.BigDecimal; |
| 6 import java.text.ParseException; |
| 7 import java.text.ParsePosition; |
| 8 import java.util.ArrayList; |
| 9 import java.util.List; |
| 10 |
| 11 import com.ibm.icu.impl.number.formatters.PaddingFormat.PadPosition; |
| 12 import com.ibm.icu.impl.number.formatters.RangeFormat; |
| 13 import com.ibm.icu.impl.number.modifiers.SimpleModifier; |
| 14 import com.ibm.icu.text.CompactDecimalFormat.CompactStyle; |
| 15 import com.ibm.icu.text.DecimalFormatSymbols; |
| 16 import com.ibm.icu.util.MeasureUnit; |
| 17 |
| 18 public class demo { |
| 19 |
| 20 public static void main(String[] args) throws ParseException { |
| 21 SimpleModifier.testFormatAsPrefixSuffix(); |
| 22 |
| 23 System.out.println(new FormatQuantity1(3.14159)); |
| 24 System.out.println(new FormatQuantity1(3.14159, true)); |
| 25 System.out.println(new FormatQuantity2(3.14159)); |
| 26 |
| 27 System.out.println( |
| 28 PatternString.propertiesToString(PatternString.parseToProperties("+**##,
##,#00.05#%"))); |
| 29 |
| 30 ParsePosition ppos = new ParsePosition(0); |
| 31 System.out.println( |
| 32 Parse.parse( |
| 33 "dd123", |
| 34 ppos, |
| 35 new Properties().setPositivePrefix("dd").setNegativePrefix("ddd"), |
| 36 DecimalFormatSymbols.getInstance())); |
| 37 System.out.println(ppos); |
| 38 |
| 39 List<Format> formats = new ArrayList<Format>(); |
| 40 |
| 41 Properties properties = new Properties(); |
| 42 Format ndf = Endpoint.fromBTA(properties); |
| 43 formats.add(ndf); |
| 44 |
| 45 properties = |
| 46 new Properties() |
| 47 .setMinimumSignificantDigits(3) |
| 48 .setMaximumSignificantDigits(3) |
| 49 .setCompactStyle(CompactStyle.LONG); |
| 50 Format cdf = Endpoint.fromBTA(properties); |
| 51 formats.add(cdf); |
| 52 |
| 53 properties = |
| 54 new Properties().setFormatWidth(10).setPadPosition(PadPosition.AFTER_PRE
FIX); |
| 55 Format pdf = Endpoint.fromBTA(properties); |
| 56 formats.add(pdf); |
| 57 |
| 58 properties = |
| 59 new Properties() |
| 60 .setMinimumExponentDigits(1) |
| 61 .setMaximumIntegerDigits(3) |
| 62 .setMaximumFractionDigits(1); |
| 63 Format exf = Endpoint.fromBTA(properties); |
| 64 formats.add(exf); |
| 65 |
| 66 properties = new Properties().setRoundingIncrement(new BigDecimal("0.5")); |
| 67 Format rif = Endpoint.fromBTA(properties); |
| 68 formats.add(rif); |
| 69 |
| 70 properties = new Properties().setMeasureUnit(MeasureUnit.HECTARE); |
| 71 Format muf = Endpoint.fromBTA(properties); |
| 72 formats.add(muf); |
| 73 |
| 74 properties = |
| 75 new Properties().setMeasureUnit(MeasureUnit.HECTARE).setCompactStyle(Com
pactStyle.LONG); |
| 76 Format cmf = Endpoint.fromBTA(properties); |
| 77 formats.add(cmf); |
| 78 |
| 79 properties = PatternString.parseToProperties("#,##0.00 \u00a4"); |
| 80 Format ptf = Endpoint.fromBTA(properties); |
| 81 formats.add(ptf); |
| 82 |
| 83 RangeFormat rf = new RangeFormat(cdf, cdf, " to "); |
| 84 System.out.println(rf.format(new FormatQuantity2(1234), new FormatQuantity2(
2345))); |
| 85 |
| 86 String[] cases = { |
| 87 "1.0", |
| 88 "2.01", |
| 89 "1234.56", |
| 90 "3000.0", |
| 91 // "512.0000000000017", |
| 92 // "4096.000000000001", |
| 93 // "4096.000000000004", |
| 94 // "4096.000000000005", |
| 95 // "4096.000000000006", |
| 96 // "4096.000000000007", |
| 97 "0.00026418", |
| 98 "0.01789261", |
| 99 "468160.0", |
| 100 "999000.0", |
| 101 "999900.0", |
| 102 "999990.0", |
| 103 "0.0", |
| 104 "12345678901.0", |
| 105 // "789000000000000000000000.0", |
| 106 // "789123123567853156372158.0", |
| 107 "-5193.48", |
| 108 }; |
| 109 |
| 110 for (String str : cases) { |
| 111 System.out.println("----------"); |
| 112 System.out.println(str); |
| 113 System.out.println(" NDF: " + ndf.format(new FormatQuantity2(Double.parse
Double(str)))); |
| 114 System.out.println(" CDF: " + cdf.format(new FormatQuantity2(Double.parse
Double(str)))); |
| 115 System.out.println(" PWD: " + pdf.format(new FormatQuantity2(Double.parse
Double(str)))); |
| 116 System.out.println(" EXF: " + exf.format(new FormatQuantity2(Double.parse
Double(str)))); |
| 117 System.out.println(" RIF: " + rif.format(new FormatQuantity2(Double.parse
Double(str)))); |
| 118 System.out.println(" MUF: " + muf.format(new FormatQuantity2(Double.parse
Double(str)))); |
| 119 System.out.println(" CMF: " + cmf.format(new FormatQuantity2(Double.parse
Double(str)))); |
| 120 System.out.println(" PTF: " + ptf.format(new FormatQuantity2(Double.parse
Double(str)))); |
| 121 } |
| 122 } |
| 123 } |
OLD | NEW |