type | SoloLearn: Learn to code for FREE!

+1

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 Answer

+5

This 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

+5

You don't like the suffix? :) Just declare them as double. That's a language specification, that's how you declare float.

+1

an integer is 4, a float is 4.0 joseph prijs

0

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...

0

Ok Thanks