浮点数后如何设置7位精度
How to set 7-digit precision after the floating point
计算梯形面积的例子
Input 5, 7, 12, Output 72.0000000
Input 8.5, 4.3, 2.7, Output 49.5000000
Input 100, 200, 300, Output 45000.0000000
Input 5, 7, 12, Output 72.0000000
Input 0.222, 0.333, 0.555, Output 0.1540125
我需要答案看起来像上面一样,后面总是有 7 位数字。
string.Format("{0:0.0000000}", 34.5223423523542);
// 34.5223424
string.Format("{0:N7}", 34.5223423523542);
// 34.5223424
如果您打算只显示一定数量的数字,您可能需要在显示之前对结果进行四舍五入。
double number = 1.23456789;
string output = Math.Round(number, 7, MidpointRounding.AwayFromZero).ToString("N7")
上面output
的值将是1.2345679
。
计算梯形面积的例子
Input 5, 7, 12, Output 72.0000000
Input 8.5, 4.3, 2.7, Output 49.5000000
Input 100, 200, 300, Output 45000.0000000
Input 5, 7, 12, Output 72.0000000
Input 0.222, 0.333, 0.555, Output 0.1540125
我需要答案看起来像上面一样,后面总是有 7 位数字。
string.Format("{0:0.0000000}", 34.5223423523542);
// 34.5223424
string.Format("{0:N7}", 34.5223423523542);
// 34.5223424
如果您打算只显示一定数量的数字,您可能需要在显示之前对结果进行四舍五入。
double number = 1.23456789;
string output = Math.Round(number, 7, MidpointRounding.AwayFromZero).ToString("N7")
上面output
的值将是1.2345679
。