Java: Format number in millions

前端 未结 8 2235
日久生厌
日久生厌 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:27

    Note that if you have a BigDecimal, you can use the movePointLeft method:

    new DecimalFormat("#.00").format(value.movePointLeft(6));
    

提交回复
热议问题