Cant use decimals when defining a value. C#

124 Views Asked by At

I have these two lines:

Int32 val3 = 8;
Int32 val4 = 0.66;

The first line works, but the second does not. I don't know why, and I don't know how I would go to fix this or what to search for.

2

There are 2 best solutions below

0
On

Try using

double val4 = 0.66

Int is for numbers without decimal points...

1
On

0.66 is not int32, it is float because it has dot (0.66), only natural numbers are Int simply use

float val4 = 0.66f

or

var val4 = 0.66

C# recognize it correctly as float at compile time