How can I format a double to have only 2 decimal places? C++

bail3yz
bail3yz used Ask the Experts™
on
I need to format a double so it only has 2 decimal places.. the length of the double is always different.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Freelance programmer / Consultant
Commented:
char s[100];
sprintf(s, ".2f", 2.33333);

now s = "2.33"

Author

Commented:
That makes s = ".2f" for me?

Author

Commented:
sprintf(s, "%.2f", 322.33333);

Works.. needed the %..

Thanks!
AndyAinscowFreelance programmer / Consultant

Commented:
sorry, not quite woken up yet.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial