an*****@gmail.c om (Andy) wrote in message news:<ad******* *************** ***@posting.goo gle.com>...

Could anyone tell me how to round off a number to certain significant

figures using C++?

For example, how to round off a number 12567 to 13000 (2 significant

figures)?

How would you do in on paper? Let me guess, you take the 3rd digit

(3, since you want to keep only 2 digits). If this third digit is

[0..4], set it and the digits following to 0. If the digit is

[5..9], increase the second digit (which may overflow, it it's 9)

and set the 3rd and following digits to 0.

Now, splitting a number into decimal digits is a bit tricky. You

need to know that the modulo operator in C++ is called '%', e.g.

25 modulo 10 is written (25%10)==5

HTH,

Michiel Salters