Boost logo

Boost Users :

From: jsanga_at_[hidden]
Date: 2007-02-28 16:23:49


Is there a way to specify the precision of doubles when writing to xml_oarchive? Refer to the output snippet below.

        <Control class_id="3" tracking_level="0" version="1">
                <Type>0</Type>
                <LowMZ>5.0499999999999998</LowMZ>
                <HiMZ>5.0999999999999996</HiMZ>

I would like 5.05 and 5.1 for Low and High. Stepping through the code with the debugger I ended up in basic_text_oprimitive::save( const double t).

   void save(const double t)
    {
        if(os.fail())
            boost::throw_exception(archive_exception(archive_exception::stream_error));
        os << std::setprecision(std::numeric_limits<double>::digits10 + 2);
        os << t;
    }

where it seems the precision is fixed. The only solution I can seem to think of is to split the serialization, and on the output convert my double to string (with the correct precsion) and then serialize the string. Is there a different or better way?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net