type
When I do the following why do i get a message that it needs to be a double? One number after a decimal point isn't float ? float x = 10.2 % 4;
2/2/2019 8:46:34 PM
joseph prijs
5 Answers
New AnswerThis is what documentation says : By default, a real numeric literal on the right side of the assignment operator is treated as double. Therefore, to initialize a float variable, use the suffix f or F, as in the following example: float x = 3.5F; If you do not use the suffix in the previous declaration, you will get a compilation error because you are trying to store a double value into a float variable. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/float
You don't like the suffix? :) Just declare them as double. That's a language specification, that's how you declare float.
Thanks! So what WOULD be considered a float? Is there anything that could validly be declared as a float without a suffix? (I know an integer could but that doesn't need float...