圆形双至两个小数位 [英] Round Double To Two Decimal Places
本文介绍了圆形双至两个小数位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将双精度数舍入为两位小数位数的最佳方法是还有它固定在小数点后两位?
What is the best way to round a double to two decimal places and also have it fixed at 2 decimal places?
例如:2.346 - > 2.35,
2 - > 2.00
Example: 2.346 -> 2.35, 2 -> 2.00
我希望避免这样的事情,我必须将一个double转换为字符串,然后回到一个双,这似乎是一个坏的方式去这个。
I am hoping to avoid something like this where I have to convert a double to string and then back to a double which seems like a bad way to go about this.
推荐答案
double someValue = 2.346;
String.Format("{0:0.00}", someValue);
这篇关于圆形双至两个小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文