• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ Question

Mears

Platinum Member
Is there a way to ensure that all values that are assigned to a certain variable are rounded off to the 10th decimal place?
 
What data type are you using? Float or double or something else? I would imagine that you would have to use the modulo function for this case. Maybe you would want to mulitply the var by 10x10 and convert it to int (to cut off the remainder) and then divide by 10x10 and convert it into a float. But thats ineffecient, I dont think that you would want to do that. My best recommendation would be to play around with the modulo function (%).
 
Hey, to convert a double varaiable say x, I thought you just had to write: int(x);

For some reason, I'm getting errors when trying this.
 
int varI = 0;
double varD = 2.57;

varI = int( varD );



edit >> woops double post during high traffic time..
 
Depending upon the order of magnitude of your number, 10 decimal places is pushing it.

Try something like

double d = f();
d = floor (d * 1.0e10) / 1.0e10;

But it isn't floor. It might be floorl, I forget. (floor is for float not double)

Moohoo
 
I tried * by 10e10 and then converting to int and then double and then finally dividing by 10e10, but the == operator still is considering them not equal. I'm starting to get pissed off. When I use cout statements and show the variables directly before they are evaluated they print off as being equal.
 
Back
Top