我面临大十进制问题。 以下代码片段将解释我的问题:
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.
更多推荐
发布评论