- Code: Select all • Expand view
double a = 42.f;
double b = 360. / 2;
1) When to use or not use the period after the number, if there is no fractional part?
2) What does it even mean?
3) When are you supposed to use f and not use f?
double a = 42.f;
double b = 360. / 2;
Nash wrote:1) When to use or not use the period after the number, if there is no fractional part?
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
Users browsing this forum: No registered users and 2 guests