From e93ac3d7eb94842161f0669cf78b4e2173dc0488 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 1 Dec 2012 11:45:04 +0200 Subject: [PATCH] Use an Fmt object to store the float format --- source/textwriter.cpp | 11 ++++++----- source/textwriter.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) 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); -- 2.43.0