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
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
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 c++ mathematics
You are not signed in. Login or sign up in order to post.
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.
– Bacco
I get it, thank you.
– Luis Souza
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.
– Bacco
Yes, I just have to convert the values from integers to floating and treat the number of houses in C++, then I put down.
– Luis Souza