Skip to content

robertlude/Nomen-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Nomen-Java

Number beautifier/namer

Quick Use

  1. Use git submodule add [email protected]:robertlude/Nomen-Java.git de/ertlu/rob/Nomen at your Java project source root directory
  2. Call Nomen.format(value) from your code

Examples

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µ

Built-In Formats

  • Nomen.EnglishShortScale
  • Nomen.EnglishLongScale
  • Nomen.SIPrefix
  • Nomen.SIPrefixAbbreviated
  • Nomen.BytesDecimal
  • Nomen.BytesDecimalAbbreviated
  • Nomen.BytesBinary
  • Nomen.BytesBinaryAbbreviated

Usage

Nomen.format

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

Nomen.GroupingMode

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

About

Number beautifier/namer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages