Hi
Hi
this code gives an error (cannot implicitely convert double to float.
float pm100, m100=10,56F;
pm100 = Math.Round(1000 + (10 - m100)*100,0);
I know the solution: pm100 = Convert.ToSingle(Math.Round(1000 + (10 - m100)*100,0));
But why can't Math.Round work with float?
Thanks

poojasree ravi13 reputationPosted Dec 4, 2021, 9:13 AM EST
When you attempt to call a method that has overloads with a type it doesn't directly support (such as calling Math.Round(float)), it will try to determine the best version to call (if any). How this is done is discussed at length in section 7.5.3 of the C# Language Specification 5.0.
Since float can be implicitly converted to a double, this means that Math.Round(Double) will be called.
Valerie MeunierRank #1,527 · 1K reputationPosted Dec 4, 2021, 12:30 PM EST