use*_*183 2 c# decimal rounding
我想将价格(加倍)四舍五入到最接近的xx.99
例如:
10.3 ==> 10.99
10 ==> 10.99
10.97 ==> 10.99
10.50 ==> 10.99
10.99 ==> 10.99
10.01 ==> 10.99
我做了Math.Round,Math.Truncate,Math.Ceiling但它不能正常工作的情况下所有.我可以转换string,拆分和替换,但我认为这不是一个好方法.
我能怎么做?
把小数点去掉并加上0.99美分;)
double value = 10.45d;
double newprice = (int)value + 0.99;
Run Code Online (Sandbox Code Playgroud)