float

hello is there any way to make a float only be 2 decimals (e.g x.xx) instead of x.xxxxx?






Last edited on
Yes you can make your output only have two decimal places, but in order to tell you how you need to show us what language you're using.

language? i'm using C++ if that's what you mean? it's when i do something like this:
0.50 - 0.15, i get more than two decimals which is annoying for the program i try to write.
Last edited on
Okay then since your using C++ you should investigate the functions prototyped in the <iomanip> header file. For example setw(), fixed, and showpoint().
okay thanks :)
A simple example would have sufficed here.

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <iomanip>

int main(int argc, const char* argv[])
{
    float pi = 3.14159;
    std::cout << std::setprecision(3) << pi << std::endl;

    return 0;
}
thanks :D
Last edited on
Topic archived. No new replies allowed.