代码如下:
1 //货币类型的两个数基本运算 2 Console.WriteLine("错误的写法"); 3 decimal errorNumA = (10 - 6); 4 decimal errorNumb = errorNumA / 10; 5 decimal errorNumC = (10 - 6) / 10; 6 7 Console.WriteLine(errorNumb); 8 Console.WriteLine(errorNumC); 9 10 11 Console.WriteLine(); 12 Console.WriteLine("正确的写法"); 13 decimal numa = (10 - 6); 14 decimal numb = numa / 10m; 15 16 decimal numc = (10 - 6) / 10m; 17 18 Console.WriteLine(numb); 19 Console.WriteLine(numc);
运行结果:
运算的时候带m单位和不带结果大相径庭。切记、切记
时间: 2024-10-12 22:50:25