gpt4 book ai didi

java - 无法将 "1,000.00"字符串解析为数字

转载 作者:行者123 更新时间:2023-12-01 06:42:53 25 4
gpt4 key购买 nike

我有几个显示数值的标签,我需要将这些文本解析为数字。问题是当值大于999时,parse方法失败并抛出以下异常:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "1,000.00" at java.lang.NumberFormatException.forInputString(Unknown Source)

我尝试了几种解析方法,例如 Double.valueOf(string)、new BigDecimal(string)new BigInteger(string) 等on...但总是抛出异常。

最佳答案

我猜您使用的是法国号码。您可以add a Locale to NumberFormatparse in the documentation :

NumberFormat.getNumberInstance(Locale.FRANCE).parse("1,000")

关于java - 无法将 "1,000.00"字符串解析为数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36328583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com