double vs float
Posted: Thu Apr 27, 2023 4:55 pm
int rate = 10; int t = 5;
XXX amount = 1000.0;
for(int i=0; i<t; t++) {
amount = amount*(1 - rate/100);
}
What can XXX be?
i am struggling to understand the difference between double and float
i know that they got different sizes:
float is Up to 7 digits after decimal and default value is 0.0f
double is Up to 15 digits after decimal and default value is 0.0d
but how do you tell whether the value is double or float? (apart from the letters d and f)
and for this question why it can only be double?
XXX amount = 1000.0;
for(int i=0; i<t; t++) {
amount = amount*(1 - rate/100);
}
What can XXX be?
i am struggling to understand the difference between double and float
i know that they got different sizes:
float is Up to 7 digits after decimal and default value is 0.0f
double is Up to 15 digits after decimal and default value is 0.0d
but how do you tell whether the value is double or float? (apart from the letters d and f)
and for this question why it can only be double?