+ 2
Float vs. int?
When testing some script, I would get an error message every time I wrote something like float x = 3/1.5; or float x = 2.6; but not float x = 3/2; however, 3/2 would come up as 1 instead of 1.5. If int uses only whole numbers, then what's the difference between float and int?
4 odpowiedzi
+ 3
This is because literals like 1 or 2 are interpreted as int. As a result operations is done with intigers. You cannot divide intiger by float without converting intiger to float first (they are not compatible). On top of that, writing 2.0 or 1.5 is not quite interpreted as float, but as double instead. Try with doubles (same as float but with higher precision - double is a default floating point type in C#). After operations are done, convert to float like here: ...=(float)(2.0/1.5).
+ 2
Simple Concept Look Here Guys For INT & Float
In Many Softwares Coding You Might Have Seen that,
Float value="5.0"
But the same in integer INT it can be wrotten as
Int ="5"
Difference:-
Float contains value after (.)
Eg:- (.something value)
Int doesn't contains that, its just a Single value
Hope, It Was Helpful , Thanks
0
integers (ints) store Whole number values like 1538 or 3
floats on the other hand store decimal values like 49.3 or 1987.57.
(doubles are more precise than floats.)
- 3
to make it simple.
Floats are Decimal Number while
Ints are While Numbers.