【发布时间】:2014-10-08 10:08:04
【问题描述】:
我想知道如何将点精度添加到十进制。我做了一个小程序来计算工人的每周工资,但在某些情况下,当结果像 145.60 美元时,它显示为 145.6 美元,但我希望程序显示结果为 145.60 美元。
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int hours;
decimal total;
Console.Write("Total working hours: ");
hours = int.Parse(Console.ReadLine());
total = Convert.ToDecimal(hours * 7.50);
if (hours > 40)
total = total + Convert.ToDecimal((hours - 40) * 3.75);
Console.WriteLine("Total weekly pay is $" + total + ".");
Console.ReadLine();
}
}
}
【问题讨论】:
-
Console.WriteLine("Total weekly pay is ${0:N2}.", total);
标签: c# .net decimal floating-point-precision