LEFT | RIGHT |
(no file at all) | |
1 // © 2017 and later: Unicode, Inc. and others. | 1 // © 2017 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 package com.ibm.icu.number; | 3 package com.ibm.icu.number; |
4 | 4 |
5 import com.ibm.icu.number.NumberFormatter.SignDisplay; | 5 import com.ibm.icu.number.NumberFormatter.SignDisplay; |
6 import com.ibm.icu.text.CompactDecimalFormat.CompactStyle; | 6 import com.ibm.icu.text.CompactDecimalFormat.CompactStyle; |
7 | 7 |
8 /** | 8 /** |
9 * A class that defines the notation style to be used when formatting numbers in
NumberFormatter. | 9 * A class that defines the notation style to be used when formatting numbers in
NumberFormatter. |
10 * | 10 * |
11 * @draft ICU 60 | 11 * @draft ICU 60 |
12 * @provisional This API might change or be removed in a future release. | 12 * @provisional This API might change or be removed in a future release. |
13 * @see NumberFormatter | 13 * @see NumberFormatter |
14 */ | 14 */ |
15 public class Notation { | 15 public class Notation { |
16 | 16 |
17 // TODO: Support engineering intervals other than 3? | 17 // TODO: Support engineering intervals other than 3? |
18 private static final ScientificNotation SCIENTIFIC = new ScientificNotation(
1, false, 1, SignDisplay.AUTO); | 18 private static final ScientificNotation SCIENTIFIC = new ScientificNotation(
1, |
19 private static final ScientificNotation ENGINEERING = new ScientificNotation
(3, false, 1, SignDisplay.AUTO); | 19 false, |
| 20 1, |
| 21 SignDisplay.AUTO); |
| 22 private static final ScientificNotation ENGINEERING = new ScientificNotation
(3, |
| 23 false, |
| 24 1, |
| 25 SignDisplay.AUTO); |
20 private static final CompactNotation COMPACT_SHORT = new CompactNotation(Com
pactStyle.SHORT); | 26 private static final CompactNotation COMPACT_SHORT = new CompactNotation(Com
pactStyle.SHORT); |
21 private static final CompactNotation COMPACT_LONG = new CompactNotation(Comp
actStyle.LONG); | 27 private static final CompactNotation COMPACT_LONG = new CompactNotation(Comp
actStyle.LONG); |
22 private static final SimpleNotation SIMPLE = new SimpleNotation(); | 28 private static final SimpleNotation SIMPLE = new SimpleNotation(); |
23 | 29 |
24 /* package-private */ Notation() { | 30 /* package-private */ Notation() { |
25 } | 31 } |
26 | 32 |
27 /** | 33 /** |
28 * Print the number using scientific notation (also known as scientific form
, standard index form, or standard form | 34 * Print the number using scientific notation (also known as scientific form
, standard index form, or |
29 * in the UK). The format for scientific notation varies by locale; for exam
ple, many Western locales display the | 35 * standard form in the UK). The format for scientific notation varies by lo
cale; for example, many |
30 * number in the form "#E0", where the number is displayed with one digit be
fore the decimal separator, zero or more | 36 * Western locales display the number in the form "#E0", where the number is
displayed with one digit |
31 * digits after the decimal separator, and the corresponding power of 10 dis
played after the "E". | 37 * before the decimal separator, zero or more digits after the decimal separ
ator, and the |
| 38 * corresponding power of 10 displayed after the "E". |
32 * | 39 * |
33 * <p> | 40 * <p> |
34 * Example outputs in <em>en-US</em> when printing 8.765E4 through 8.765E-3: | 41 * Example outputs in <em>en-US</em> when printing 8.765E4 through 8.765E-3: |
35 * | 42 * |
36 * <pre> | 43 * <pre> |
37 * 8.765E4 | 44 * 8.765E4 |
38 * 8.765E3 | 45 * 8.765E3 |
39 * 8.765E2 | 46 * 8.765E2 |
40 * 8.765E1 | 47 * 8.765E1 |
41 * 8.765E0 | 48 * 8.765E0 |
42 * 8.765E-1 | 49 * 8.765E-1 |
43 * 8.765E-2 | 50 * 8.765E-2 |
44 * 8.765E-3 | 51 * 8.765E-3 |
45 * 0E0 | 52 * 0E0 |
46 * </pre> | 53 * </pre> |
47 * | 54 * |
48 * @return A ScientificNotation for chaining or passing to the NumberFormatt
er notation() setter. | 55 * @return A ScientificNotation for chaining or passing to the NumberFormatt
er notation() setter. |
49 * @draft ICU 60 | 56 * @draft ICU 60 |
50 * @provisional This API might change or be removed in a future release. | 57 * @provisional This API might change or be removed in a future release. |
51 * @see NumberFormatter | 58 * @see NumberFormatter |
52 */ | 59 */ |
53 public static ScientificNotation scientific() { | 60 public static ScientificNotation scientific() { |
54 return SCIENTIFIC; | 61 return SCIENTIFIC; |
55 } | 62 } |
56 | 63 |
57 /** | 64 /** |
58 * Print the number using engineering notation, a variant of scientific nota
tion in which the exponent must be | 65 * Print the number using engineering notation, a variant of scientific nota
tion in which the |
59 * divisible by 3. | 66 * exponent must be divisible by 3. |
60 * | 67 * |
61 * <p> | 68 * <p> |
62 * Example outputs in <em>en-US</em> when printing 8.765E4 through 8.765E-3: | 69 * Example outputs in <em>en-US</em> when printing 8.765E4 through 8.765E-3: |
63 * | 70 * |
64 * <pre> | 71 * <pre> |
65 * 87.65E3 | 72 * 87.65E3 |
66 * 8.765E3 | 73 * 8.765E3 |
67 * 876.5E0 | 74 * 876.5E0 |
68 * 87.65E0 | 75 * 87.65E0 |
69 * 8.765E0 | 76 * 8.765E0 |
70 * 876.5E-3 | 77 * 876.5E-3 |
71 * 87.65E-3 | 78 * 87.65E-3 |
72 * 8.765E-3 | 79 * 8.765E-3 |
73 * 0E0 | 80 * 0E0 |
74 * </pre> | 81 * </pre> |
75 * | 82 * |
76 * @return A ScientificNotation for chaining or passing to the NumberFormatt
er notation() setter. | 83 * @return A ScientificNotation for chaining or passing to the NumberFormatt
er notation() setter. |
77 * @draft ICU 60 | 84 * @draft ICU 60 |
78 * @provisional This API might change or be removed in a future release. | 85 * @provisional This API might change or be removed in a future release. |
79 * @see NumberFormatter | 86 * @see NumberFormatter |
80 */ | 87 */ |
81 public static ScientificNotation engineering() { | 88 public static ScientificNotation engineering() { |
82 return ENGINEERING; | 89 return ENGINEERING; |
83 } | 90 } |
84 | 91 |
85 /** | 92 /** |
86 * Print the number using short-form compact notation. | 93 * Print the number using short-form compact notation. |
87 * | 94 * |
88 * <p> | 95 * <p> |
89 * <em>Compact notation</em>, defined in Unicode Technical Standard #35 Part
3 Section 2.4.1, prints numbers with | 96 * <em>Compact notation</em>, defined in Unicode Technical Standard #35 Part
3 Section 2.4.1, prints |
90 * localized prefixes or suffixes corresponding to different powers of ten.
Compact notation is similar to | 97 * numbers with localized prefixes or suffixes corresponding to different po
wers of ten. Compact |
91 * engineering notation in how it scales numbers. | 98 * notation is similar to engineering notation in how it scales numbers. |
92 * | 99 * |
93 * <p> | 100 * <p> |
94 * Compact notation is ideal for displaying large numbers (over ~1000) to hu
mans while at the same time minimizing | 101 * Compact notation is ideal for displaying large numbers (over ~1000) to hu
mans while at the same |
95 * screen real estate. | 102 * time minimizing screen real estate. |
96 * | 103 * |
97 * <p> | 104 * <p> |
98 * In short form, the powers of ten are abbreviated. In <em>en-US</em>, the
abbreviations are "K" for thousands, "M" | 105 * In short form, the powers of ten are abbreviated. In <em>en-US</em>, the
abbreviations are "K" for |
99 * for millions, "B" for billions, and "T" for trillions. Example outputs in
<em>en-US</em> when printing 8.765E7 | 106 * thousands, "M" for millions, "B" for billions, and "T" for trillions. Exa
mple outputs in |
100 * through 8.765E0: | 107 * <em>en-US</em> when printing 8.765E7 through 8.765E0: |
101 * | 108 * |
102 * <pre> | 109 * <pre> |
103 * 88M | 110 * 88M |
104 * 8.8M | 111 * 8.8M |
105 * 876K | 112 * 876K |
106 * 88K | 113 * 88K |
107 * 8.8K | 114 * 8.8K |
108 * 876 | 115 * 876 |
109 * 88 | 116 * 88 |
110 * 8.8 | 117 * 8.8 |
111 * </pre> | 118 * </pre> |
112 * | 119 * |
113 * <p> | 120 * <p> |
114 * When compact notation is specified without an explicit rounding strategy,
numbers are rounded off to the closest | 121 * When compact notation is specified without an explicit rounding strategy,
numbers are rounded off |
115 * integer after scaling the number by the corresponding power of 10, but wi
th a digit shown after the decimal | 122 * to the closest integer after scaling the number by the corresponding powe
r of 10, but with a digit |
116 * separator if there is only one digit before the decimal separator. The de
fault compact notation rounding strategy | 123 * shown after the decimal separator if there is only one digit before the d
ecimal separator. The |
117 * is equivalent to: | 124 * default compact notation rounding strategy is equivalent to: |
118 * | 125 * |
119 * <pre> | 126 * <pre> |
120 * Rounder.integer().withMinDigits(2) | 127 * Rounder.integer().withMinDigits(2) |
121 * </pre> | 128 * </pre> |
122 * | 129 * |
123 * @return A CompactNotation for passing to the NumberFormatter notation() s
etter. | 130 * @return A CompactNotation for passing to the NumberFormatter notation() s
etter. |
124 * @draft ICU 60 | 131 * @draft ICU 60 |
125 * @provisional This API might change or be removed in a future release. | 132 * @provisional This API might change or be removed in a future release. |
126 * @see NumberFormatter | 133 * @see NumberFormatter |
127 */ | 134 */ |
128 public static CompactNotation compactShort() { | 135 public static CompactNotation compactShort() { |
129 return COMPACT_SHORT; | 136 return COMPACT_SHORT; |
130 } | 137 } |
131 | 138 |
132 /** | 139 /** |
133 * Print the number using long-form compact notation. For more information o
n compact notation, see | 140 * Print the number using long-form compact notation. For more information o
n compact notation, see |
134 * {@link #compactShort}. | 141 * {@link #compactShort}. |
135 * | 142 * |
136 * <p> | 143 * <p> |
137 * In long form, the powers of ten are spelled out fully. Example outputs in
<em>en-US</em> when printing 8.765E7 | 144 * In long form, the powers of ten are spelled out fully. Example outputs in
<em>en-US</em> when |
138 * through 8.765E0: | 145 * printing 8.765E7 through 8.765E0: |
139 * | 146 * |
140 * <pre> | 147 * <pre> |
141 * 88 million | 148 * 88 million |
142 * 8.8 million | 149 * 8.8 million |
143 * 876 thousand | 150 * 876 thousand |
144 * 88 thousand | 151 * 88 thousand |
145 * 8.8 thousand | 152 * 8.8 thousand |
146 * 876 | 153 * 876 |
147 * 88 | 154 * 88 |
148 * 8.8 | 155 * 8.8 |
149 * </pre> | 156 * </pre> |
150 * | 157 * |
151 * @return A CompactNotation for passing to the NumberFormatter notation() s
etter. | 158 * @return A CompactNotation for passing to the NumberFormatter notation() s
etter. |
152 * @draft ICU 60 | 159 * @draft ICU 60 |
153 * @provisional This API might change or be removed in a future release. | 160 * @provisional This API might change or be removed in a future release. |
154 * @see NumberFormatter | 161 * @see NumberFormatter |
155 */ | 162 */ |
156 public static CompactNotation compactLong() { | 163 public static CompactNotation compactLong() { |
157 return COMPACT_LONG; | 164 return COMPACT_LONG; |
158 } | 165 } |
159 | 166 |
160 /** | 167 /** |
161 * Print the number using simple notation without any scaling by powers of t
en. This is the default behavior. | 168 * Print the number using simple notation without any scaling by powers of t
en. This is the default |
| 169 * behavior. |
162 * | 170 * |
163 * <p> | 171 * <p> |
164 * Since this is the default behavior, this method needs to be called only w
hen it is necessary to override a | 172 * Since this is the default behavior, this method needs to be called only w
hen it is necessary to |
165 * previous setting. | 173 * override a previous setting. |
166 * | 174 * |
167 * <p> | 175 * <p> |
168 * Example outputs in <em>en-US</em> when printing 8.765E7 through 8.765E0: | 176 * Example outputs in <em>en-US</em> when printing 8.765E7 through 8.765E0: |
169 * | 177 * |
170 * <pre> | 178 * <pre> |
171 * 87,650,000 | 179 * 87,650,000 |
172 * 8,765,000 | 180 * 8,765,000 |
173 * 876,500 | 181 * 876,500 |
174 * 87,650 | 182 * 87,650 |
175 * 8,765 | 183 * 8,765 |
176 * 876.5 | 184 * 876.5 |
177 * 87.65 | 185 * 87.65 |
178 * 8.765 | 186 * 8.765 |
179 * </pre> | 187 * </pre> |
180 * | 188 * |
181 * @return A SimpleNotation for passing to the NumberFormatter notation() se
tter. | 189 * @return A SimpleNotation for passing to the NumberFormatter notation() se
tter. |
182 * @draft ICU 60 | 190 * @draft ICU 60 |
183 * @provisional This API might change or be removed in a future release. | 191 * @provisional This API might change or be removed in a future release. |
184 * @see NumberFormatter | 192 * @see NumberFormatter |
185 */ | 193 */ |
186 public static SimpleNotation simple() { | 194 public static SimpleNotation simple() { |
187 return SIMPLE; | 195 return SIMPLE; |
188 } | 196 } |
189 } | 197 } |
LEFT | RIGHT |