When to use float and integer? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

When to use float and integer?

5th Apr 2017, 10:17 PM
Khadija Afzaal
Khadija Afzaal - avatar
5 Answers
+ 1
float when you need a decimal. integer when you need a whole number example integer for counting number of people (you cant have a fraction of a person) float for calculating area of a circle also, i prefer using double instead of float
5th Apr 2017, 10:19 PM
Edward
+ 1
yea you can use int instead of float, as 10 and 20 are whole numbers
5th Apr 2017, 10:29 PM
Edward
+ 1
it should work. try it and check again for errors
5th Apr 2017, 10:29 PM
Edward
0
float a =10; float b = 20; float c = a+b; console.WriteLine (c); console.ReadKey ( ); can i use int instead of float here?? but if i do so it's not working
5th Apr 2017, 10:26 PM
Khadija Afzaal
Khadija Afzaal - avatar
0
yeah working thank u so much :)
5th Apr 2017, 10:34 PM
Khadija Afzaal
Khadija Afzaal - avatar