Use setprecision to save number to variable

I'm trying to compare two numbers to each other, but only to a certain decimal point.
For instance, 3.1459 to 3.1429. I wish to use setprecision to be able to say that these two numbers are the same (up to 3 digits). How can this be accomplished?
What does std::setprecision have to do with the problem?

Compute the difference in magnitude between the two values and compare to the desired epsilon. For example, two floating point numbers x and y differ in magnitude by less than roughly one thousandth if and only if
std::abs(y - x) < 0.001;

N.B.: this is not the correct way to test for approximate floating-point equality - but you didn't ask for that.
Last edited on
@mbozzi Great idea, I don't know why I didn't think of that. Thank you!
Topic archived. No new replies allowed.