我是一名有用的助手,可以为您进行翻译。
以下是需要翻译的内容:
以下是需要翻译的内容:
可能会有重复:
如何正确四舍五入和格式化小数?
我有这个:
double xValue = 0.0;
double yValue = 0.0;
foreach (var line in someList)
{
xValue = Math.Round(Convert.ToDouble(xDisplacement - xOrigin), 2);
yValue= Math.Round(Convert.ToDouble(yDisplacement + yOrigin), 2);
sw.WriteLine("( {0}, {1} )", xValue, yValue);
}
当进行数学计算时,应该将数字四舍五入到2位小数。
然而,
.. 当数字为6.397之类的数字时,它会将其舍入为6.4并不包括末尾的"0"。
如何在数字末尾添加"0"?
如果我将此添加到上面的foreach循环之前(除非有更好的方法?):
string properX = xValue.ToString().Replace(".", "");
string properY = yValue.ToString().Replace(".", "");
我该如何处理这个问题?
xDisplacement - xOrigin
吗?我不知道您的应用程序是什么,但通常是从原点减去位移,而不是相反。 - Daniel Renshaw