Quick simple C++ question

MiataGirl

Banned
Sep 2, 2002
309
0
0
Okay so I created some equation to calculate a number..but now I only want it to display 2 decimal points, using iomanip functions. I can manipulate the TOTAL number of characters that it shows..but how do I control how many decimal points??
 

MiataGirl

Banned
Sep 2, 2002
309
0
0
Hmm, that seems a little complex for me. I was thinking along the lines of commands such as setw, setprecision, and the likes..
 

BigJ

Lifer
Nov 18, 2001
21,330
1
81
i'm pretty sure this can be done including stdio.h and calling a function named something like setprecision or setprec, something like that. Look in the file and it tells u all the functions in it.
 
Jun 18, 2000
11,215
781
126
setprecision(n) is included in iomanip.h. Use it like so:

C++ Code:
#include <iomanip.h>
int main(){
double d_numTest = 3.123456;
cout << setprecision(4) << d_numTest << endl;
return 0;
}

Output:
3.1235
 

BigJ

Lifer
Nov 18, 2001
21,330
1
81
Originally posted by: KnightBreed
setprecision(n) is included in iomanip.h. Use it like so:

C++ Code:
int main(){

double d_numTest = 3.123456;

cout << setprecision(4) << d_numTest << endl;

return 0;
}

Output:
3.1235

Give the man a cookie :) , thats exactly what I was thinking off, would've known it if I wasn't taking java now instead of brushing up on C++
 
Jun 18, 2000
11,215
781
126
Originally posted by: BigJ2078
Give the man a cookie :) , thats exactly what I was thinking off, would've known it if I wasn't taking java now instead of brushing up on C++
You had the right idea. I think all that Java is poisoning your mind.