Jan 10, 2020 in JAVA
Q: Compact Number Formatting JAVA 12 feature

1 Answer

0 votes
Jan 10, 2020

import java.text.NumberFormat;

import java.util.Locale;

public class CompactNumberFormatting {

    public static void main(String[] args)

    {

        System.out.println("Compact Formatting is:");

        NumberFormat upvotes = NumberFormat

                .getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.SHORT);

        upvotes.setMaximumFractionDigits(1);

        System.out.println(upvotes.format(2592) + " upvotes");

        NumberFormat upvotes2 = NumberFormat

                .getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.LONG);

        upvotes2.setMaximumFractionDigits(2);

        System.out.println(upvotes2.format(2011) + " upvotes");

    }

}

 

Related questions

0 votes
Apr 20, 2020 in JAVA
  • #java12
0 votes
Jan 10, 2020 in JAVA
+1 vote
May 27, 2019 in Other
0 votes
Oct 23, 2020 in JAVA
...