C ++でsetprecision(2)を使用して桁を丸めようとすると、「0.093」のような数値が返されます。小数点以下2桁ではなく、3桁です。これがなぜなのか理解できません。いくつかの点が大幅に欠落している場合に備えて、非常に基本的なコードを以下に含めました。ありがとう!
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double tax = 0.06 ; //Tax Rate
float cost ; //Cost of item
float computed ; //Non-rounded tax
cout << "Enter the cost of the item: " ;
cin >> cost ;
computed = tax*cost;
cout << "Computed: $" << computed << endl;
cout << "Charged: $" << setprecision(2) << computed << endl; //Computed tax rounded to 2 decimal places
return 0;
}