Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetPrecision, really need help !

Status
Not open for further replies.

ellyrion

Programmer
Jun 5, 2002
1
BE
here's the thing: I must have a project ready by the day after tomorrow. It's all working except for one little thingy, I must have precision in my float. So for example when the solution is 15.4834573154 it must come 15.48 ! I tried with a mask but then I become 15.480000000 . I know it's something with SetPrecision command, but I tried everything I know and it just doesn't work :-(. Can someone help me please!!!
greetz
yalk
 
I'm assumming that you are using streams.
Code:
double ExpSQ_M = 1234.4583;
//OFile << setprecision(3) << ExpSq_M << endl;  // Square Meters to an output file
cout << setprecision(3) << ExpSq_M << endl;  // Square Meters
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that they think I am now
qualified to do anything with nothing.
 
I forgot to mention that you will need to include the iomanip.h file.
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that they think I am now
qualified to do anything with nothing.
 
or another cheap and dirty way is

float Example = 23.544566;
float Item;
int Temp = (float / .01);
Item = Temp *.01;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top