Convert a String to Double - Java

前端 未结 5 2040
慢半拍i
慢半拍i 2020-11-27 19:51

What is the easiest and correct way to convert a String number with commas (for example: 835,111.2) to a Double instance.

Thanks.

5条回答
  •  清歌不尽
    2020-11-27 19:58

    Use java.text.DecimalFormat:

    DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits. It also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). All of these can be localized.

提交回复
热议问题