in JAVA by
Compact Number Formatting JAVA 12 feature

1 Answer

0 votes
by

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
asked Jan 10, 2020 in JAVA by DavidAnderson
0 votes
asked Dec 12, 2019 in JAVA by AdilsonLima
0 votes
asked Apr 21, 2020 in JAVA by Hodge
...