Java Decimal Format - as much precision as given

前端 未结 2 867
难免孤独
难免孤独 2021-01-18 21:53

I\'m working with DecimalFormat, I want to be able to read and write decimals with as much precision as given (I\'m converting to BigDecimal).

2条回答
  •  没有蜡笔的小新
    2021-01-18 22:40

    Since you noted in a comment that you need Locale support:

    Locale locale = //get this from somewhere else
    DecimalFormat df = new DecimalFormat();
    df.setDecimalFormatSymbols(new DecimalFormatSymbols(locale));
    df.setMaximumFractionDigits(Integer.MAX_VALUE);
    df.setMinimumFractionDigits(1);
    df.setParseBigDecimal(true);
    

    And then parse.

提交回复
热议问题