BigDecimal Constructor采取有效的数字串。
The String representation consists of an optional sign,
‘+’ (‘\u002B’) or ‘-‘ (‘\u002D’), followed by a sequence of zero or
more decimal digits (“the integer”), optionally followed by a
fraction, optionally followed by an exponent.
String salePrice = "$348.00";
String price = salePrice.replace("$","");
BigDecimal sPrice = new BigDecimal(price);
System.out.println(sPrice);
输出= 348.00
你也可以看看NumberFormat课。使用这个类可以设置相应的区域设置。
String salePrice = "$123.45";
Locale locale = Locale.US;
Number number = NumberFormat.getCurrencyInstance(locale).parse(salePrice);
System.out.println(number);
输出= 123.45