Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按时双重格式化_C#_Format_Double - Fatal编程技术网

C# 按时双重格式化

C# 按时双重格式化,c#,format,double,C#,Format,Double,如何将TotalHours设置为双格式,或者如何将93.3的结果设置为txtBoxMonatstotal。 这是我的代码: private void calendar1_MonthChanged(object sender, EventArgs e) { DateTime start = new DateTime(calendar1.CurrentDate.Year, calendar1.CurrentDate.Month, 1); DateTime stop = new Dat

如何将
TotalHours
设置为双格式,或者如何将
93.3
的结果设置为
txtBoxMonatstotal
。 这是我的代码:

private void calendar1_MonthChanged(object sender, EventArgs e)
{
    DateTime start = new DateTime(calendar1.CurrentDate.Year, calendar1.CurrentDate.Month, 1);
    DateTime stop = new DateTime(calendar1.CurrentDate.Year, calendar1.CurrentDate.Month, 1).AddMonths(1).AddDays(-1);
    int numberOfWorkDays = GetNumberOfWorkingDays(start, stop);

    double shouldWorkPerMonth = tag_durschnit * numberOfWorkDays;
    double workedPerMonth = workingHours.Where(x => x.Key.Date.Year == start.Year && x.Key.Month == start.Month).Sum(x => x.Value.TotalHours);
    double saldo = workedPerMonth - shouldWorkPerMonth;

    txtBoxMonatstotal.Text = workedPerMonth.ToString();
    txtBoxSollzeit.Text = shouldWorkPerMonth.ToString();
    txtBoxSaldo.Text = saldo.ToString();

}
当前结果如下所示:
 

感谢您的帮助

您需要先拨打电话号码,然后再拨打
ToString

txtBoxMonatstotal.Text = System.Math.Round(workedPerMonth, 1).ToString();
Round
中的第二个参数决定

返回值中的小数位数


在将值转换为字符串之前,先对其进行四舍五入。这是您应该做的:
Math.Round(workedPerMonth).ToString(“N1”)
。或者您可以格式化您的输出,尝试处理格式:
workedPerMonth.ToString(“00.0”)
非常感谢@MongZhu这是正确的workedPerMonth.ToString(“00.0”)