summary refs log tree commit diff stats
path: root/qapi/string-output-visitor.c
diff options
context:
space:
mode:
authorMichael Roth <mdroth@linux.vnet.ibm.com>2012-04-30 09:33:30 -0500
committerAndreas Färber <afaerber@suse.de>2012-06-08 16:11:14 +0200
commit173bbb754f53e8bfc8e4d488f2ed66fe1072ed69 (patch)
treed807452d835e39e512a5784c1f773b877fbe4a6b /qapi/string-output-visitor.c
parent2d496105397b8eca905f9a53c40e2faaac7bfa6b (diff)
downloadfocaccia-qemu-173bbb754f53e8bfc8e4d488f2ed66fe1072ed69.tar.gz
focaccia-qemu-173bbb754f53e8bfc8e4d488f2ed66fe1072ed69.zip
qapi: String visitor, use %f representation for floats
Currently string-output-visitor formats floats as %g, which is nice in
that trailing 0's are automatically truncated, but otherwise this causes
some issues:

 - it uses 6 significant figures instead of 6 decimal places, which
   means something like 155777.5 (which even has an exact floating point
   representation) will be rounded to 155778 when converted to a string.

 - output will be presented in scientific notation when the normalized
   form requires a 10^x multiplier. Not a huge deal, but arguably less
   readable for command-line arguments.

 - due to using scientific notation for numbers requiring more than 6
   significant figures, instead of hard-defined decimal places, it
   fails a lot of the test-visitor-serialization unit tests for floats.

Instead, let's just use %f, which is what the QJSON and the QMP visitors
use.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'qapi/string-output-visitor.c')
-rw-r--r--qapi/string-output-visitor.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c
index 92b0305212..34e525eadd 100644
--- a/qapi/string-output-visitor.c
+++ b/qapi/string-output-visitor.c
@@ -52,7 +52,7 @@ static void print_type_number(Visitor *v, double *obj, const char *name,
                               Error **errp)
 {
     StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v);
-    string_output_set(sov, g_strdup_printf("%g", *obj));
+    string_output_set(sov, g_strdup_printf("%f", *obj));
 }
 
 char *string_output_get_string(StringOutputVisitor *sov)