0

can we use double in place of int or not?

int sum1 = 1000 / 5; //can we use double in place of int or not

4th May 2020, 4:28 PM
Sudip Giri
Sudip Giri - avatar
3 ответов
+ 2
Sudip Giri you can use double in place of int but you will not see much of a difference because 1000/5 is completely divisible and would return 200 as int and 200.0 as double. Try double sum1 = 1000/6; It will give you 166.0 and not the exact result because both the numbers are of type int, you atleast need to have one number of type double to get the exact answer. double sum1 = 1000/6.0; This will give 166.66... which is the exact result. Hope I'm clear.
4th May 2020, 4:42 PM
Avinesh
Avinesh - avatar
+ 2
int cannot contain decimal point but double can be used to store a number which contains decimal point
4th May 2020, 4:31 PM
Souptik Nath
Souptik Nath - avatar
0
Yes ofcourse but it take more memory int takes 2 bits float takes 8 bits
4th May 2020, 4:31 PM
Abhay
Abhay - avatar