I'd like to read a floating point value cin >> Value where Value is declared as a double and then output it to a string justified to two decimal places. I understand how to do it using a temporary file, but I'd like to avoid that method and sprintf() if possible

Recommended Answers

sorry but cant you use setwidth function ? Or something similar?

Jump to Post

That accomplishes the formatting I want, but still doesn't solve the problem of assigning it to a string variable.

Not sure if I know what I'm talking about here, but couldnt you put your double / float into an array then convert the array to a string?

Jump to Post

All 5 Replies

sorry but cant you use setwidth function ? Or something similar?

sorry but cant you use setwidth function ? Or something similar?

That accomplishes the formatting I want, but still doesn't solve the problem of assigning it to a string variable.

That accomplishes the formatting I want, but still doesn't solve the problem of assigning it to a string variable.

Not sure if I know what I'm talking about here, but couldnt you put your double / float into an array then convert the array to a string?

Thanks Dave, just what I was looking for and much more!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.