Просмотр исходного кода

Test casting a JsonValue to a float

Benoit Blanchon 11 лет назад
Родитель
Сommit
6384bc414a
2 измененных файлов с 10 добавлено и 0 удалено
  1. 5 0
      JsonGenerator/JsonValue.h
  2. 5 0
      JsonGeneratorTests/JsonValue_Cast_Tests.cpp

+ 5 - 0
JsonGenerator/JsonValue.h

@@ -74,6 +74,11 @@ namespace ArduinoJson
                 return content.asDouble;
                 return content.asDouble;
             }
             }
 
 
+            operator float()
+            {
+                return (float)content.asDouble;
+            }
+
             operator int()
             operator int()
             {
             {
                 return content.asLong;
                 return content.asLong;

+ 5 - 0
JsonGeneratorTests/JsonValue_Cast_Tests.cpp

@@ -30,6 +30,11 @@ namespace JsonGeneratorTests
             setValueAndCheckCast(3.14156);
             setValueAndCheckCast(3.14156);
         }
         }
 
 
+        TEST_METHOD(Float)
+        {
+            setValueAndCheckCast(3.14f);
+        }
+
         TEST_METHOD(Integer)
         TEST_METHOD(Integer)
         {
         {
             setValueAndCheckCast(42);
             setValueAndCheckCast(42);