1

I would like a way to force at least 1 decimal to appear in the result of an integer division.

int a = 2, b = 1;
std::cout << a/(double)b;
>>>> 2
int a = 2, b = 1;
std::cout << (1.0*a)/(1.0*b);
>>>> 2

I would like to print 2.0 but only gets 2 trying above tricks.

Answer:

std::cout.precision(1);
std::cout << std::fixed << a/(double)b;
user12392864
  • 288
  • 1
  • 3
  • 11

0 Answers0