Skip to content
Reference > Methods

formatNumberCompact(value)

Definition

String formatNumberCompact(Number value)

Description

Converts a numeric value to short string using suffixes (max of 4 chars, or 5 for negative numbers)

Parameter Definition

Name Type Description
value Number value to convert to string

Examples

String r1 = formatNumberCompact(1); // r1 == 1
String r2 = formatNumberCompact(12); // r2 == 12
String r3 = formatNumberCompact(123); // r3 == 123
String r4 = formatNumberCompact(1234); // r4 == 1.2k
String r5 = formatNumberCompact(12345); // r5 == 12k
String r6 = formatNumberCompact(123456); // r6 == 123k
String r7 = formatNumberCompact(1234567); // r7 == 1.2m
String r8 = formatNumberCompact(12345678); // r8 == 12m
String r9 = formatNumberCompact(0.1D); // r9 == .1
String r10 = formatNumberCompact(0.2D); // r10 == .2
String r11 = formatNumberCompact(0.3D); // r11 == .3
String r12 = formatNumberCompact(0.4D); // r12 == .4
String r13 = formatNumberCompact(0.5D); // r13 == .5
String r14 = formatNumberCompact(-0.5D); // r14 == -.5