例如即時得到6-12的區域爲三角形,我需要我的輸出顯示006.000需要我的輸出要以這種形式XXX.XXX C++
我知道setprecision會做的伎倆限制的小數位到三個,但我如何將零置於我的解決方案前面?
這是我所擁有的
CTriangle Sides(3,4,5);
cout << std::fixed << std::setprecision(3);
cout << "\n\n\t\tThe perimeter of this tringle is = " << Sides.Perimeter();
cout << "\n\n\t\tThe area of the triangle is = " << Sides.Area();
cout << "\n\n\t\tThe angle one is = " << Sides.Angleone();
cout << "\n\n\t\tThe angle two is = " << Sides.Angletwo();
cout << "\n\n\t\tThe angle three is = " << Sides.Anglethree();
cout << "\n\n\t\tThe altitude one of the triangle = " << Sides.Altitudeone();
cout << "\n\n\t\tThe altitude two of the triangle = " << Sides.Altitudetwo();
cout << "\n\n\t\tThe altitude three of the triangle = " << Sides.Altitudethree();
與輸出是
The perimeter of this triangle is = 12.000
The area of the triangle is = 6.000
The angle one is = 90.000
The angle two is = 36.870
The angle three is = 53.130
The altitude one of the triangle = 2.400
The altitude two of the triangle = 6.667
The altitude three of the triangle = 3.750
,但我需要所有的答案是這種形式XXX.XXX不管我的解決方案是什麼。(因爲該值會改變)
任何幫助表示讚賞,謝謝!
記得也設置'固定'和'精確' – example
當然,這些是除了提供的代碼 –
這就是它,謝謝一堆 – user3185727