medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit cdddc73c84f3bf8710d0fd243e04af1a8eca4fcb
parent dc7d356b347dbf6a69d70247297bb3ca49b6d662
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Mar 25 02:05:33 +0200

More intuitive float width formatting. e.g. {2.3} -> xx.yyy

Diffstat:
ggformat.cc | 9++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/ggformat.cc b/ggformat.cc @@ -47,12 +47,11 @@ static void format_helper( FormatBuffer * fb, const ShortString & fmt, const T & void format( FormatBuffer * fb, double x, const FormatOpts & opts ) { ShortString fmt; fmt += "%"; + int precision = opts.precision != -1 ? opts.precision : 5; if( opts.left_align ) fmt += "-"; - if( opts.width != -1 ) fmt += opts.width; - if( opts.precision != -1 ) { - fmt += "."; - fmt += opts.precision; - } + if( opts.width != -1 ) fmt += opts.width + 1 + precision; + fmt += "."; + fmt += opts.precision; fmt += "f"; format_helper( fb, fmt, x ); }