设置BigDecimal的特定精度 [英] Set specific precision of a BigDecimal

查看:2128
本文介绍了设置BigDecimal的特定精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XSD ,要求我使用BigDecimal作为lat / lon。我目前将lat / lon作为双精度,并将它们转换为BigDecimal,但我只需要使用大约12个精度位置。我无法弄清楚如何设置它。任何人都可以帮我吗?

I have an XSD that requires me to use a BigDecimal for a lat/lon. I currently have the lat/lon as doubles, and convert them to BigDecimal, but I am only required to use about 12 places of precision. I have not been able to figure out how to set that. Can anyone help me with this?

推荐答案

你可以使用 setScale()例如

double d = ...
BigDecimal db = new BigDecimal(d).setScale(12, BigDecimal.ROUND_HALF_UP);

这篇关于设置BigDecimal的特定精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆