测试用例3过不了,为什么88.8-80=7.99999?

P5705 【深基2.例7】数字反转

Go_for_itligli666666 @ 2022-03-28 21:18:12

#include<iostream>
using namespace std;
int main()
{
    float num;
    cin>>num;
    float out=0;
    //num/100*0.001,n/10*0.01,n/1*0.1,n/0.1*1
    float i=100;
    while(i>=0.1)
    {
        int temp=num/i;
        out+=temp*(1/(10*i));
        num-=i*temp;
        i/=10;
    }
    cout<<out<<endl;
    return 0;
}

by Keep_RAD @ 2022-03-28 21:24:47

精度问题,要像:80.8-80.0=0.8


|