Need to round decimal stored as a string
Posted on 2004-08-04
I have a std:string with a decimal value. I want to round this to a certain number of decimal places.
For example, I have "38.987654321" and I want to round it to 3 places, I want to get "38.988".
I can convert this to a float, use the pow function to shift it (38987.654321), add .5, truncate, shift it back, and set it back to a string.
Is there an easier way?
I would like to use a double rather than a float. How would I do that?