Double Length

I have a double read from an input file. I'm not sure if it is bigger than 10 or less than 10, but I always want it to come out as five characters (including the decimal). So, if it is 10.321789, I want to truncate it to 10.32. But if it is 9.98765, I want to truncate it to 9.987 (or 9.988 if possible). Is there an easy way to do this, without checking if the double is >= 10?

Thanks.
In addition, I'm converting these doubles to strings, so maybe I could cut of the string length...
closed account (zwA4jE8b)
You can use a string stream to convert any number into a string.
Then you will just have to resize your string :)

Although, that will not help you with rounding.
try using setprecision()
Last edited on
How do I resize a string? I'm not too concerned with rounding.

I thought setprecision() was only good for output.
Nevermind, I figured it out. Thanks for the suggestion.
What was your solution??
Last edited on
i can't understand what are you mean ! but i think your solution is precision for all of number or fixed for just set in number of after point :-??
Topic archived. No new replies allowed.