diff --git a/JsonGenerator/JsonValue.h b/JsonGenerator/JsonValue.h index 3ba9e2d7..fc167499 100644 --- a/JsonGenerator/JsonValue.h +++ b/JsonGenerator/JsonValue.h @@ -74,6 +74,11 @@ namespace ArduinoJson return content.asDouble; } + operator float() + { + return (float)content.asDouble; + } + operator int() { return content.asLong; diff --git a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp index 591cb690..68c93f9f 100644 --- a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp +++ b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp @@ -30,6 +30,11 @@ namespace JsonGeneratorTests setValueAndCheckCast(3.14156); } + TEST_METHOD(Float) + { + setValueAndCheckCast(3.14f); + } + TEST_METHOD(Integer) { setValueAndCheckCast(42);