Java: Format number in millions

前端 未结 8 2238
日久生厌
日久生厌 2020-12-10 14:01

Is there a way to use DecimalFormat (or some other standard formatter) to format numbers like this:

1,000,000 => 1.00M

1,234,567 =>

8条回答
  •  生来不讨喜
    2020-12-10 14:52

    For now, you should use ICU's CompactDecimalFormat, which will localize the formatting result for non-english locales. Other locales might not use a "Millions" suffix.

    This functionality will be standard Java in JDK 12 with CompactNumberFormat.

提交回复
热议问题