Code: Select all
double a = 42.f;
double b = 360. / 2;
2) What does it even mean?
3) When are you supposed to use f and not use f?
Code: Select all
double a = 42.f;
double b = 360. / 2;
Forgot to answer that one. When you add the period that number becomes a double, while if you leave it out the number is an integer. Here's some examples:Nash wrote:1) When to use or not use the period after the number, if there is no fractional part?
Code: Select all
int a = 5 / 2; // result is 2, because its an integer division
double b = 5 / 2; // result is still 2, because it is an integer division, then converted to a double
double c = 5. / 2; // result is 2.5, because a double divided by an integer is a floating point division
double d = 5 / 2.; // result is 2.5, same reason
double e = 5 / 2 + 5. / 2; // result is 4.5 - first part is an integer division, second part is a float