For some reason I keep getting an error saying 'Cannot implicitly convert type double to float' All over my code. I bolded and left a comment exactly where in my code I'm getting the errors. I cant seem to figure out what the problem is. I switched the data types all to 'double' instead of 'float' and the program ran smoothly with no errors. Can some one please tell me what I am doing wrong or what is missing from the code? (Edit: Bold does not seem to work on my code on this site).
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- Correctly parse PDF paragraphs with Python
- 求获取指定qq 资料的方法
The problem is that when you perform your multiplication (or other arithmetic operation) you are working with a literal such as 0.15. This value by default will be treated as a double by the compiler and so when multiplied against a float it results in the larger double result. To get around this you need to mark the literals as .15f so that they are treated as float literals.
In addition to Phil's suggestion you should use float.TryParse instead of float.Parse otherwise you might get FormatException if user enters invlaid text