•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,788 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,788 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 363 | Replies: 6 | Solved
![]() |
•
•
Join Date: Oct 2007
Location: Cambridge, MA
Posts: 247
Reputation:
Rep Power: 1
Solved Threads: 21
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,630
Reputation:
Rep Power: 8
Solved Threads: 168
•
•
•
•
Using <iomanip> and setprecision() but I cant seem to get it to work.
Could someone please give me a small example.
ok:
cpp Syntax (Toggle Plain Text)
float a = 0.00012354684; //number has 8 meaningfull digits (skip the first zero's) cout << setprecision (8) << a << "\n"; cout << setprecision (5) << a << "\n"; cout << setprecision (3) << a << "\n"; cout << setprecision (1) << a << "\n";
output:
0.00012354684 0.00012355 0.000124 0.0001
What doesn't work in your program? Post your code.
Last edited by niek_e : Jul 18th, 2008 at 5:27 am.
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
do NOT pm me for help, in the best case, you'll get ignored
do NOT pm me for help, in the best case, you'll get ignored
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,630
Reputation:
Rep Power: 8
Solved Threads: 168
•
•
•
•
- is there something I should be aware of when dividing 2 numbers in C++?
- thats why I am getting no decimal points?
try this:
cpp Syntax (Toggle Plain Text)
float a = 1.2, b = 0.5; int c = 2, d = 3; cout << "two floats: " << a/b << "\n"; cout << "two ints: " << d/c << "\n"; cout << "float and int: " << a/c << "\n";
2.4 1 0.6
Last edited by niek_e : Jul 18th, 2008 at 5:55 am.
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
do NOT pm me for help, in the best case, you'll get ignored
do NOT pm me for help, in the best case, you'll get ignored
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Two Decimal Places (VB.NET)
- problem with decimal places (Visual Basic 4 / 5 / 6)
- C++ question(Decimal places)very weird (C++)
- Excel97 decimal places (Windows Software)
- setting the number of decimal points in double varibale (C)
- Using Decimal Numbers instead of Integers in C (C)
Other Threads in the C++ Forum
- Previous Thread: C++ anonymous emailer
- Next Thread: Mixed type multitude without using Struct




Linear Mode