0

Why don't we just use double instead of int

isn't double better for storing any kind of numerical data, so why do we use int?

24th Aug 2018, 9:00 AM
Basil Amazing
Basil Amazing - avatar
3 odpowiedzi
+ 3
double uses more space, which probably isn't a huge concern nowadays. Still, sometimes it's useful to make it clear that the intended value is an integer and will not have a decimal part
24th Aug 2018, 9:16 AM
Dan Walker
Dan Walker - avatar
+ 5
Also, apart from memory allocation size, whole number arithmetic operations are faster than floating points arithmetic operations. Plus, there are places where floating points usage doesn't make sense, for example, when we refer to an element's index in an array, or when we iterate in loops, using floating point types for loop iterator will cause problem, because iterator value isn't precise.
24th Aug 2018, 9:34 AM
Ipang
0
Dan Walker thanks
24th Aug 2018, 9:22 AM
Basil Amazing
Basil Amazing - avatar