Categories

Jan 10 in JAVA

Q: Compact Number Formatting JAVA 12 feature

1 Answer

Jan 10

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");

    }

}

 

Click here to read more about JAVA
Click here to read more about Insurance

Related questions

Madanswer
May 27, 2019 in Other
Oct 18 in JAVA
Feb 13 in JAVA
...