You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/api/number/number-formatter.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,10 @@ Optional. String with rounding method `ceil`, `floor`, `round` (default), or `tr
30
30
31
31
Optional. Boolean (default is true) value indicating whether a grouping separator should be used.
32
32
33
+
#### options.compact
34
+
35
+
Optional. String `short` or `long` indicating which compact number format should be used to represent the number.
36
+
33
37
### Examples
34
38
35
39
#### Static Formatter
@@ -139,6 +143,30 @@ frFormatter( 0.0005 );
139
143
// > "0,05 %"
140
144
```
141
145
146
+
#### Formatting Compact Numbers
147
+
148
+
Long numbers can be represented in a compact format, with `short` using abbreviated units and `long` using the full unit name.
149
+
150
+
```javascript
151
+
var shortFormatter =Globalize( "en" ).numberFormatter({
152
+
compact:"short",
153
+
maximumFractionDigits:0,
154
+
style:"decimal"
155
+
});
156
+
157
+
var longFormatter =Globalize( "en" ).numberFormatter({
158
+
compact:"long",
159
+
maximumFractionDigits:0,
160
+
style:"decimal"
161
+
});
162
+
163
+
shortFormatter( 27588910 );
164
+
// > "28M"
165
+
166
+
longFormatter( 27588910 );
167
+
// > "28 million"
168
+
```
169
+
142
170
#### Configuring Rounding
143
171
144
172
Numbers with a decreased amount of decimal places can be rounded up, rounded down, rounded arithmetically, or truncated by setting the `round` option to `ceil`, `floor`, `round` (default), or `truncate`.
0 commit comments