大十进制解析问题(Big Decimal parsing problem)

编程入门 行业动态 更新时间:2024-10-23 00:23:24
大十进制解析问题(Big Decimal parsing problem)

我面临大十进制问题。 以下代码片段将解释我的问题:

BigDecimal parsedValue = (BigDecimal) decimalFormat.parse(input);

这里输入是一个字符串类型。 现在假设输入的值是135abc24,在这种情况下,parsedValue的值是135,但我想检查这样的输入并给出错误而不是截断字符串和其余部分。 只想添加输入字符串也可能包含指数nos,所以我甚至无法检查数字字符串。 如果您想了解更多信息或问题尚未明确,请与我们联系,

提前致谢。

I am facing problem in big decimal no. Following code snippet will explain my problem:

BigDecimal parsedValue = (BigDecimal) decimalFormat.parse(input);

Here input is a string type. Now suppose value of input is 135abc24 in this case value of parsedValue is 135 but i want to check for such inputs and give an error instead of truncating the string and rest of part. Just want to add input string may also contains exponential nos, so i cant even check for only numeric strings. Please let me know if you want further information or or question is not clear,

Thanks in advance.

最满意答案

您可以使用BigDecimal的String构造函数来创建BigDecimal(有关详细信息,请参阅链接),并在您的输入字符串之前应用您希望的任何转换。 如果输入不是有效表示,则构造函数抛出NumberFormatException 。

You can use BigDecimal's String constructor to create the BigDecimal (see the link for details) and apply any transformations you wish to your input string beforehands. The constructor throws a NumberFormatException if the input is not a valid representation.

更多推荐

本文发布于:2023-04-27 15:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327173.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Big   大十进制   Decimal   problem   parsing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!