使用 Java 将超过 20 位的字符串转换为数字
Convert string with more than 20 digits to a number using Java
我有这个字符串:
0.023526112354180534
如何将此字符串转换为数字,甚至更多数字?我试过 Double.parseDouble 但没用
编辑
你是对的。
我正在从 Javascript 拨打电话,我的电话是:
url : "/myapp/data/selectedCampaign/thermal/"+data
数据=0.023526112354180534
当我在Spring
中输入这个方法时
@RequestMapping(value = "/selectedCampaign/{type}/{evidenceValue}", method = RequestMethod.GET)
public @ResponseBody List<Double> getValues(@PathVariable("type") String type,
@PathVariable("evidenceValue") String evidenceValue)
evidenceValue 是 0 而我正在解析 0
我还是不知道为什么。
编辑 2
我通过以下方式解决了这个问题:
Spring MVC @PathVariable with dot (.) is getting truncated
使用new BigDecimal("0.023526112354180534");
double d = Double.parseDouble("0.023526112354180534");
System.out.println(d);
对我来说没有问题,至少没有精度损失
编辑:据我所知 Double.parseDouble(String) 和 BigDecimal 之间的唯一区别是精度,所以如果精度很重要,你应该使用 BigDecimal
我有这个字符串:
0.023526112354180534
如何将此字符串转换为数字,甚至更多数字?我试过 Double.parseDouble 但没用
编辑
你是对的。
我正在从 Javascript 拨打电话,我的电话是:
url : "/myapp/data/selectedCampaign/thermal/"+data
数据=0.023526112354180534
当我在Spring
中输入这个方法时@RequestMapping(value = "/selectedCampaign/{type}/{evidenceValue}", method = RequestMethod.GET)
public @ResponseBody List<Double> getValues(@PathVariable("type") String type,
@PathVariable("evidenceValue") String evidenceValue)
evidenceValue 是 0 而我正在解析 0
我还是不知道为什么。 编辑 2
我通过以下方式解决了这个问题:
Spring MVC @PathVariable with dot (.) is getting truncated
使用new BigDecimal("0.023526112354180534");
double d = Double.parseDouble("0.023526112354180534");
System.out.println(d);
对我来说没有问题,至少没有精度损失
编辑:据我所知 Double.parseDouble(String) 和 BigDecimal 之间的唯一区别是精度,所以如果精度很重要,你应该使用 BigDecimal