有小数的金额,如果有的话要修剪到小数点后两位
最佳答案
您是否尝试过使用 value = Decimal.Round(value, 2)
?
例如:
using System;
class Test
{
static void Main()
{
decimal d = 1234.5678m;
Console.WriteLine("Before: {0}", d); // Prints 1234.5678
d = decimal.Round(d, 2);
Console.WriteLine("After: {0}", d); // Prints 1234.57
}
}
请注意,这是四舍五入而不仅仅是修整(所以这里是四舍五入)...您到底需要什么? Decimal
结构有可能支持您需要做的任何事情。咨询MSDN更多选项。
关于c# - 有小数金额,如果存在,要修剪到 2 位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4695053/