圆满一双至3位有效数字 [英] Round a double to 3 significant figures
本文介绍了圆满一双至3位有效数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人知道如何将双倍数值舍入到3个重要数字,例如本网站上的示例
Does anybody know how I can round a double value to 3 significant figures like the examples on this website
http://www.purplemath.com/modules/rounding2.htm
推荐答案
double d = ...;
BigDecimal bd = new BigDecimal(d);
bd = bd.round(new MathContext(3));
double rounded = bd.doubleValue();
这篇关于圆满一双至3位有效数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文