@@ -208,6 +208,59 @@ public function testToHuman()
208
208
$ this ->assertSame ('-1 thousand quadrillion ' , Number::forHumans (-1000000000000000000 ));
209
209
}
210
210
211
+ public function testSummarize ()
212
+ {
213
+ $ this ->assertSame ('1 ' , Number::abbreviate (1 ));
214
+ $ this ->assertSame ('1.00 ' , Number::abbreviate (1 , precision: 2 ));
215
+ $ this ->assertSame ('10 ' , Number::abbreviate (10 ));
216
+ $ this ->assertSame ('100 ' , Number::abbreviate (100 ));
217
+ $ this ->assertSame ('1K ' , Number::abbreviate (1000 ));
218
+ $ this ->assertSame ('1.00K ' , Number::abbreviate (1000 , precision: 2 ));
219
+ $ this ->assertSame ('1K ' , Number::abbreviate (1000 , maxPrecision: 2 ));
220
+ $ this ->assertSame ('1K ' , Number::abbreviate (1230 ));
221
+ $ this ->assertSame ('1.2K ' , Number::abbreviate (1230 , maxPrecision: 1 ));
222
+ $ this ->assertSame ('1M ' , Number::abbreviate (1000000 ));
223
+ $ this ->assertSame ('1B ' , Number::abbreviate (1000000000 ));
224
+ $ this ->assertSame ('1T ' , Number::abbreviate (1000000000000 ));
225
+ $ this ->assertSame ('1Q ' , Number::abbreviate (1000000000000000 ));
226
+ $ this ->assertSame ('1KQ ' , Number::abbreviate (1000000000000000000 ));
227
+
228
+ $ this ->assertSame ('123 ' , Number::abbreviate (123 ));
229
+ $ this ->assertSame ('1K ' , Number::abbreviate (1234 ));
230
+ $ this ->assertSame ('1.23K ' , Number::abbreviate (1234 , precision: 2 ));
231
+ $ this ->assertSame ('12K ' , Number::abbreviate (12345 ));
232
+ $ this ->assertSame ('1M ' , Number::abbreviate (1234567 ));
233
+ $ this ->assertSame ('1B ' , Number::abbreviate (1234567890 ));
234
+ $ this ->assertSame ('1T ' , Number::abbreviate (1234567890123 ));
235
+ $ this ->assertSame ('1.23T ' , Number::abbreviate (1234567890123 , precision: 2 ));
236
+ $ this ->assertSame ('1Q ' , Number::abbreviate (1234567890123456 ));
237
+ $ this ->assertSame ('1.23KQ ' , Number::abbreviate (1234567890123456789 , precision: 2 ));
238
+ $ this ->assertSame ('490K ' , Number::abbreviate (489939 ));
239
+ $ this ->assertSame ('489.9390K ' , Number::abbreviate (489939 , precision: 4 ));
240
+ $ this ->assertSame ('500.00000M ' , Number::abbreviate (500000000 , precision: 5 ));
241
+
242
+ $ this ->assertSame ('1MQ ' , Number::abbreviate (1000000000000000000000 ));
243
+ $ this ->assertSame ('1BQ ' , Number::abbreviate (1000000000000000000000000 ));
244
+ $ this ->assertSame ('1TQ ' , Number::abbreviate (1000000000000000000000000000 ));
245
+ $ this ->assertSame ('1QQ ' , Number::abbreviate (1000000000000000000000000000000 ));
246
+ $ this ->assertSame ('1KQQ ' , Number::abbreviate (1000000000000000000000000000000000 ));
247
+
248
+ $ this ->assertSame ('0 ' , Number::abbreviate (0 ));
249
+ $ this ->assertSame ('-1 ' , Number::abbreviate (-1 ));
250
+ $ this ->assertSame ('-1.00 ' , Number::abbreviate (-1 , precision: 2 ));
251
+ $ this ->assertSame ('-10 ' , Number::abbreviate (-10 ));
252
+ $ this ->assertSame ('-100 ' , Number::abbreviate (-100 ));
253
+ $ this ->assertSame ('-1K ' , Number::abbreviate (-1000 ));
254
+ $ this ->assertSame ('-1.23K ' , Number::abbreviate (-1234 , precision: 2 ));
255
+ $ this ->assertSame ('-1.2K ' , Number::abbreviate (-1234 , maxPrecision: 1 ));
256
+ $ this ->assertSame ('-1M ' , Number::abbreviate (-1000000 ));
257
+ $ this ->assertSame ('-1B ' , Number::abbreviate (-1000000000 ));
258
+ $ this ->assertSame ('-1T ' , Number::abbreviate (-1000000000000 ));
259
+ $ this ->assertSame ('-1.1T ' , Number::abbreviate (-1100000000000 , maxPrecision: 1 ));
260
+ $ this ->assertSame ('-1Q ' , Number::abbreviate (-1000000000000000 ));
261
+ $ this ->assertSame ('-1KQ ' , Number::abbreviate (-1000000000000000000 ));
262
+ }
263
+
211
264
protected function needsIntlExtension ()
212
265
{
213
266
if (! extension_loaded ('intl ' )) {
0 commit comments