我目前正在显示一个四舍五入到小数点后 3 位的数字,例如0.31,使用 Math.Pow,唯一的问题是我想显示这个数字 0.310(出于样式目的)有人知道这是否可能吗?
最佳答案
Fixed-Point Format Specifier可用于调用 ToString
或 string.Format
:
double x = 1493.1987;
string s1 = x.ToString("F3");
string s2 = string.Format("Your total is {0:F3}, have a nice day.", x);
// s1 is "1493.199"
// s2 is "Your total is 1493.199, have a nice day."
请注意,定点格式说明符将始终显示您指定的小数位数。例如:
double y = 1493;
string s3 = y.ToString("F3");
// s3 is "1493.000"
关于c# - 如何始终在小数点后显示 3 个数字#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36533130/