Number beautifier/namer
- Use
git submodule add [email protected]:robertlude/Nomen-Java.git de/ertlu/rob/Nomenat your Java project source root directory - Call
Nomen.format(value)from your code
| Value | Mode | Decimal Places | Result |
|---|---|---|---|
| 123.456 | -- | -- | 123 |
| 123.456 | -- | 2 | 123.45 |
| 1234.567 | -- | -- | 1.234 thousand |
| 1234.567 | -- | 2 | 1.234 thousand |
| 12345.678 | -- | -- | 12.34 thousand |
| 123456.789 | -- | -- | 123.4 thousand |
| 1234567.89 | -- | -- | 1.234 million |
| 1234567890.123 | -- | -- | 1.234 billion |
| 1234567890.123 | Nomen.EnglishLongScale |
-- | 1.234 milliard |
| 0.0000123456789 | Nomen.SIPrefixAbbreviated |
-- | 12.34µ |
Nomen.EnglishShortScaleNomen.EnglishLongScaleNomen.SIPrefixNomen.SIPrefixAbbreviatedNomen.BytesDecimalNomen.BytesDecimalAbbreviatedNomen.BytesBinaryNomen.BytesBinaryAbbreviated
String Nomen.format(BigDecimal value[, GroupingMode mode[, int decimalPlaces]]);
| Attribute | Description | Default |
|---|---|---|
value |
The value to format | -- |
mode |
The details of how to format to string | Nomen.EnglishShortScale |
decimalPlaces |
The number of maximum decimal places to display if 1 < abs(value) < groupingMode.groupSize |
0 |
| Input | Output |
|---|---|
0 == abs(value) |
"0" and appropriate label |
abs(value) < 1 |
4 significant digits and appropriate label |
1 < abs(value) < groupingMode.groupSize |
Full precision truncated at specified decimal place and appropriate label |
groupingMode.groupSize < abs(value) |
4 significant digits and appropriate label |
new Nomen.GroupingMode(int groupSize, String labelMid, String[] labelLarge, String[] labelSmall)
new Nomen.GroupingMode(int groupSize, String labelMid, List<String> labelLarge, List<String> labelSmall)
| Attribute | Description |
|---|---|
groupSize |
Determines the value grouping size. Use 1000 for English and metric scales. Use 1024 for byte sizes. |
labelMid |
The suffix to use if a value is less than groupSize and greater than or equal to one |
labelLarge |
A list of suffixes to use if a value is greater than or equal to groupSize |
labelSmall |
A list of suffixes to use if a value is less than 1 |
See source for example implementations