diff --git a/runtime/vm/json_test.cc b/runtime/vm/json_test.cc index 17463283afd..d25d01de716 100644 --- a/runtime/vm/json_test.cc +++ b/runtime/vm/json_test.cc @@ -61,7 +61,7 @@ TEST_CASE(JSON_JSONStream_Primitives) { JSONArray jsarr(&js); jsarr.AddValue(1.0); } - EXPECT_STREQ("[1.000000]", js.ToCString()); + EXPECT_STREQ("[1.0]", js.ToCString()); } { JSONStream js; diff --git a/runtime/vm/json_writer.cc b/runtime/vm/json_writer.cc index 77112ae99c6..587bf1586f3 100644 --- a/runtime/vm/json_writer.cc +++ b/runtime/vm/json_writer.cc @@ -5,6 +5,7 @@ #include "platform/assert.h" #include "platform/unicode.h" +#include "vm/double_conversion.h" #include "vm/json_writer.h" #include "vm/object.h" @@ -117,8 +118,13 @@ void JSONWriter::PrintValue64(int64_t i) { } void JSONWriter::PrintValue(double d) { + // Max length of a double in characters (including \0). + // See double_conversion.cc. + const size_t kBufferLen = 25; + char buffer[kBufferLen]; + DoubleToCString(d, buffer, kBufferLen); PrintCommaIfNeeded(); - buffer_.Printf("%f", d); + buffer_.Printf("%s", buffer); } static const char base64_digits[65] = diff --git a/runtime/vm/metrics_test.cc b/runtime/vm/metrics_test.cc index 6ca672632c0..4482a6d0faf 100644 --- a/runtime/vm/metrics_test.cc +++ b/runtime/vm/metrics_test.cc @@ -67,7 +67,7 @@ VM_UNIT_TEST_CASE(Metric_OnDemand) { "{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":" "\"foobar\",\"unit\":\"byte\"," "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\"" - ",\"value\":99.000000}", + ",\"value\":99.0}", json); } Dart_ShutdownIsolate();