Rounding down to 2 decimal places in c#

前端 未结 7 2234
渐次进展
渐次进展 2020-12-03 10:07

How can I multiply two decimals and round the result down to 2 decimal places?

For example if the equation is 41.75 x 0.1 the result will be 4.175. If I do this in c

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 10:11

    As of .NET Core 3.0 and the upcoming .NET Framework 5.0 the following is valid

    Math.Round(41.75 * 0.1, 2, MidpointRounding.ToZero))
    

提交回复
热议问题