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