Hey there. Just started learning programming on codeacademy, decided to start with C#. In the course, i have to use writeline to print the weight of a dog, a fractional number , “65.22”, it should be small enough for it to be included in the float library and decimal should be big enough to include it as well, right? but i get an error using any of them, and i can only use double, anybody knows why that is?
Hello @py9357380041, welcome to the forums! Can you post your code with a screenshot of the error, please?
I think this occurs because the default decimal number on C# is
double (meaning to create floats or decimals, you have to do things with the number, such as add an
f to the beginning of it), it wants to convert the number
65.22 to a
float, but since that’s a lossy conversion (meaning data could be lost, as floats hold less information than doubles), you have to actually tell the code you want it converted.