How to print fraction in floating point format?

Asked

Viewed 104 times

0

How can I print a fraction in the floating format in C++? I searched what this format would look like, but found nothing. E.g :

5

__

3

  • 4

    5 over 3 is the same as 5.0 / 3.0 (the decimal point is to force the treatment as floating). If put only 5/3 will be considered integer.

  • I get it, thank you.

  • If this is the only problem, post the solution in the field below (of answers) and mark as accepted (with the green V next to the points) to close the subject here on the site. I didn’t post it as an answer because I don’t know if that’s all your doubt.

  • Yes, I just have to convert the values from integers to floating and treat the number of houses in C++, then I put down.

1 answer

0

Solution

std::cout.unsetf(std::ios::floatfield);

std::cout.precision(2);

std::cout << "\n\033[36mFração\033[37m : " << static_cast< float >(this->numerador) << " \033[31m-\033[37m " << static_cast< float >(this->denominador) << "\n";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.