自 7.2.0 版本以来,某些浮点数被截短了很大部分。

作者: Arduinux创建于 2025年9月12日更新于 2025年11月18日
标签bugv7

#ifndef ARDUINO_ESP32_DEV #error - Board mismatch. "ESP32 Dev Module" required. #endif /* ARDUINO_ESP32_DEV */

#define ARDUINOJSON_USE_DOUBLE 1 #include <ArduinoJson.h>

void setup() { Serial.begin(115200);

delay(500);

Serial.println(); Serial.println("================================================================================"); Serial.println(); Serial.print("ArduinoJson-Version: "); Serial.println(ARDUINOJSON_VERSION);

double doubleA = 0.001403982; double doubleB = 0.001043521; double doubleC = 0.033841712; double doubleD = 0.025639649; double doubleE = 0.000292723;

JsonDocument testDouble; testDouble["testA"] = doubleA; testDouble["testB"] = doubleB; testDouble["testC"] = doubleC; testDouble["testD"] = doubleD; testDouble["testE"] = doubleE;

String strTestDouble; serializeJson(testDouble, strTestDouble); Serial.println(); Serial.println(strTestDouble);

JsonDocument testJson; deserializeJson(testJson, strTestDouble);

Serial.println(); Serial.println(testJson["testA"].as(), 9); Serial.println(testJson["testB"].as(), 9); Serial.println(testJson["testC"].as(), 9); Serial.println(testJson["testD"].as(), 9); Serial.println(testJson["testE"].as(), 9);

String strTestJson; Serial.println(); serializeJson(testJson, strTestJson); Serial.println(strTestJson); }

Expected output:

内容来源: bblanchon/ArduinoJson