Cout long double issue

前端 未结 4 1650
一向
一向 2021-01-14 06:01

So, I\'m working on a C++ project. I have a var of long double type and assigned it a value like \"1.02\"

Then, I try to use cout to print it and the result is: -0

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-14 06:48

    This is an easier method, but your program worked on my compiler.

    #include 
    #include 
    #include 
    
    using namespace std;
    
    int main(int argc, char** argv)
    {
    
        std::setprecision(10);
        long double var = 1.023563457578;
        cout << var << endl;
        return 0;
    }
    

    I hope this helps you see that your compiler might actually have a problem.

    Source - > Link

提交回复
热议问题