Tuesday, July 14, 2009

C++ Decimal Number Problems(Im using a database with this C++ progrm) PLEASE HELP?

Im using c++ to build a program to view a datatbase and creating queries. I have a feild in the database that contains numbers with decimals and when i view the database in c++ (via a DbGrd) there are like 30 numbers after the decimal. How do i get c++ to just show the number and 2 decimal places? I have also tried setting the number on decimal places in the actuall database to 2 but in c++ it still shows loads of numbers after the decimal place. e.g. 0.31534534543534 when all i need it to be is 0.31. Any help would be great thanks

C++ Decimal Number Problems(Im using a database with this C++ progrm) PLEASE HELP?
You can format the output of cout like this:


cout %26lt;%26lt; setprecision(2) %26lt;%26lt; yourVar %26lt;%26lt; endl;





And if you want it to show the decimal even when it is .00, use cout %26lt;%26lt; fixed %26lt;%26lt; ...





And while we're at it, if you want to make your output even prettier, you might want to make use of setw(), setfill(), and left/right...





Oh, and to use any of those, you need to #include %26lt;iomanip%26gt;

pokemon cards

No comments:

Post a Comment