X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Ftextwriter.cpp;h=65f4870ea6e466816ee25d9dd40dbc550d00faa8;hb=19179a622c1de88de5ed7047643eec79f285bf2a;hp=eb3aa2d2f6ec778b0411228e6ac6b2f21533e3ce;hpb=e5d760ccfaaa01884be2424b62e47a24466e0c4b;p=libs%2Fdatafile.git diff --git a/source/textwriter.cpp b/source/textwriter.cpp index eb3aa2d..65f4870 100644 --- a/source/textwriter.cpp +++ b/source/textwriter.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspdatafile -Copyright © 2007-2008, 2010 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include #include "statement.h" @@ -16,9 +9,15 @@ namespace Msp { namespace DataFile { TextWriter::TextWriter(IO::Base &o): - WriterMode(o) + WriterMode(o), + float_format("%#.7g") { } +void TextWriter::set_float_precision(unsigned fp) +{ + float_format = format("%%#.%dg", fp/4-1); +} + void TextWriter::write(const Statement &st) { write_(st, 0); @@ -39,7 +38,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("%15g", (i->get()))); + out.write(format(float_format, i->get())); else if(i->get_signature()==SymbolType::signature) { string name = i->get().name;