按时格式化双重格式

时间:2018-01-22 09:00:11

标签: c# format double

如何将ERROR_ACCESS_DENIED设置为双倍格式,或者我需要做些什么才能在TotalHours txtBoxMonatstotal中获得结果93.3。 这是我的代码:

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();

}

目前的结果如下:
txtBoxMonatstotal

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您需要先round号码,然后点击ToString

txtBoxMonatstotal.Text = System.Math.Round(workedPerMonth, 1).ToString();

Round中的第二个参数确定

  

返回值中的小数位数。