0 OmniX 21 9 Years Ago I am trying to get quite a large number 0.00012354684 to X required decimal places. Using <iomanip> and setprecision() but I cant seem to get it to work. Could someone please give me a small example. Thankyou, Regards X c++

0 sarehu 84 9 Years Ago How large is X? What is the type of your large number? 0.00012354584 is actually quite small :D

0 OPDiscussion Starter OmniX 21 9 Years Ago number = 0.00012354684 type = float decimal points vary = 1-5

0 ArkM 1,090 9 Years Ago Use double (~16 decimal digits); 32-bit floats keep only ~5-7 decimal digits. Always use double type in math calculations!

0 Nick Evan 4,005 9 Years Ago Using <iomanip> and setprecision() but I cant seem to get it to work. Could someone please give me a small example. ok: 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.

0 OPDiscussion Starter OmniX 21 9 Years Ago Nice work niek_e again! I found my problem: - is there something I should be aware of when dividing 2 numbers in C++? - thats why I am getting no decimal points? Another small example, please? :) Thankyou, Regards X

1 Featured Reply Nick Evan 4,005 9 Years Ago - is there something I should be aware of when dividing 2 numbers in C++? - thats why I am getting no decimal points? try this: 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"; output 2.4 1 0.6 so the answer is: yes. Dividing 2 ints will result in loss of decimal point. But that's kind of obvious right? Votes + Comments OmniX: Thanks for the hints