From: Mikko Rasa Date: Sat, 1 Dec 2012 09:45:04 +0000 (+0200) Subject: Use an Fmt object to store the float format X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e93ac3d7eb94842161f0669cf78b4e2173dc0488;p=libs%2Fdatafile.git Use an Fmt object to store the float format --- diff --git a/source/textwriter.cpp b/source/textwriter.cpp index c870ba0..f37b733 100644 --- a/source/textwriter.cpp +++ b/source/textwriter.cpp @@ -10,13 +10,14 @@ namespace Msp { namespace DataFile { TextWriter::TextWriter(Output &o): - WriterMode(o), - float_format("%#.7g") -{ } + WriterMode(o) +{ + float_format.showpoint().precision(7); +} void TextWriter::set_float_precision(unsigned fp) { - float_format = format("%%#.%dg", fp/4-1); + float_format.precision(fp/4-1); } void TextWriter::write(const Statement &st) @@ -39,7 +40,7 @@ void TextWriter::write_(const Statement &st, unsigned level) else if(i->get_signature()==IntType::signature) out.write(lexical_cast(i->get())); else if(i->get_signature()==FloatType::signature) - out.write(format(float_format, i->get())); + out.write(lexical_cast(i->get(), float_format)); else if(i->get_signature()==SymbolType::signature) { string name = i->get().name; diff --git a/source/textwriter.h b/source/textwriter.h index e265d2f..fef4379 100644 --- a/source/textwriter.h +++ b/source/textwriter.h @@ -9,7 +9,7 @@ namespace DataFile { class TextWriter: public WriterMode { private: - std::string float_format; + Fmt float_format; public: TextWriter(Output &o);