存储与2位精度的双 [英] Storing a double with 2 digit precision
本文介绍了存储与2位精度的双的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何转换成一个双有2位精度
How do I convert a double to have precision of 2 places?
有关前:
double x = 1.00d;
Console.WriteLine(Math.Round(x,2,MidpointRounding.AwayFromZero));
//Should output 1.00 for me, but it outputs just 1.
我'什么我想找是存储在1.00打印了安慰打印时1.00的双重变量。
What I'm looking for is to store 1.00 in a double variable which when printed to console prints 1.00.
谢谢,
-Mike
Thanks, -Mike
推荐答案
×专卖店的数量 - 它并不注重精度
"x" stores the number - it doesn't pay attention to the precision.
要输出数量的作为一个字符串的与精度的具体金额,使用格式说明,即:
To output the number as a string with a specific amount of precision, use a format specifier, ie:
Console.WriteLine(x.ToString("F2"));
这篇关于存储与2位精度的双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文