Menu

Double value rounded after parsing

dmotion
2010-11-07
2013-04-22
  • dmotion

    dmotion - 2010-11-07

    Testing this, Visual C++ 2010:

    Json::Value value;
    Json::Reader reader;
    const string t = "{ \"PI\": 3.14159265 }";
    reader.parse(t, value, false);
    cout << value["PI"] << endl;
    

    Result:

    3.000000000000
    

    I solved by replacing this code:

    // json_reader.cpp
    bool Reader::decodeDouble( Token &token )
    {
        const std::string s = std::string(token.start_, token.end_);
        std::istringstream stm(s);
        double value;
        if ( !(stm >> value) ) {
           return addError( "'" + s + "' is not a number.", token );
        }
        currentValue() = value;
        return true;
    }
    
     
  • dmotion

    dmotion - 2010-11-11

    Solution to the problem without changing code:

    setlocale(LC_NUMERIC, "C");
    

    Русская специфика :)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.