mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Added a JsonValue constructor for float
This commit is contained in:
		| @@ -15,22 +15,24 @@ size_t JsonValue::printBoolTo(Print& p) const | ||||
| size_t JsonValue::printDoubleTo(Print& p) const | ||||
| { | ||||
|     char tmp[32]; | ||||
|     sprintf(tmp, "%.17lg", content.asDouble); | ||||
|     return p.write(tmp); | ||||
| } | ||||
|  | ||||
|     sprintf(tmp, "%lg", content.asDouble); | ||||
|  | ||||
| size_t JsonValue::printFloatTo(Print& p) const | ||||
| { | ||||
|     char tmp[16]; | ||||
|     sprintf(tmp, "%.9g", content.asFloat); | ||||
|     return p.write(tmp); | ||||
| } | ||||
|  | ||||
| size_t JsonValue::printLongTo(Print& p) const | ||||
| { | ||||
|     char tmp[32]; | ||||
|  | ||||
|     sprintf(tmp, "%ld", content.asLong); | ||||
|  | ||||
|     return p.write(tmp); | ||||
| } | ||||
|  | ||||
|  | ||||
| size_t JsonValue::printPrintableTo(Print& p) const | ||||
| { | ||||
|     if (content.asPrintable) | ||||
|   | ||||
| @@ -28,6 +28,12 @@ public: | ||||
|         content.asDouble = value; | ||||
|     } | ||||
|  | ||||
|     JsonValue(float value) | ||||
|         : implementation(&JsonValue::printFloatTo) | ||||
|     { | ||||
|         content.asFloat = value; | ||||
|     } | ||||
|      | ||||
|     JsonValue(long value) | ||||
|         : implementation(&JsonValue::printLongTo) | ||||
|     { | ||||
| @@ -62,6 +68,7 @@ private: | ||||
|     { | ||||
|         bool        asBool; | ||||
|         double      asDouble; | ||||
|         float       asFloat; | ||||
|         long        asLong; | ||||
|         Printable*  asPrintable; | ||||
|         const char* asString; | ||||
| @@ -73,6 +80,7 @@ private: | ||||
|  | ||||
|     size_t printBoolTo(Print& p) const; | ||||
|     size_t printDoubleTo(Print& p) const; | ||||
|     size_t printFloatTo(Print& p) const; | ||||
|     size_t printLongTo(Print& p) const; | ||||
|     size_t printPrintableTo(Print& p) const; | ||||
|     size_t printStringTo(Print& p) const; | ||||
|   | ||||
| @@ -85,11 +85,18 @@ namespace JsonGeneratorTests | ||||
|             assertResultIs("\"\\t\""); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(Float) | ||||
|         { | ||||
|             write(3.40282346e38F); | ||||
|            // assertReturns(4); | ||||
|             assertResultIs("3.40282347e+038"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(Double) | ||||
|         { | ||||
|             write(3.14); | ||||
|             assertReturns(4); | ||||
|             assertResultIs("3.14"); | ||||
|             write(1.7976931348623157e308); | ||||
|             // assertReturns(4); | ||||
|             assertResultIs("1.7976931348623157e+308"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(Integer) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user