C#: Multiply Decimal with Float?

2020-04-05 02:54发布

问题:

I want to perform the following operation:

decimal = decimal? * float / 100

What's the most efficient way to do this?

回答1:

Do you want the result as a float

var result = ((float)d) * f / 100;

or as a decimal

var result = d * ((decimal)f) / 100;

I certainly question the mixing of decimal and float types though. Some context would help!



标签: c# .net asp.net