Hi,
There’s a float number, time in seconds with milliseconds that is formated to print it to terminal, it works ok however when such number is converted to string and sent as json, the decimals leading zero is lost, for example: 3.018 is print correctly in console, however browser receives 3.18, so question is, how to avoid that and keep decimals leading zero?
Code:
uint32_t lapSeconds = (nowInner – lastTriggerInner) / 1000;
innerLapMilliseconds = (nowInner – lastTriggerInner) % 1000;
Serial.print(lapSeconds);
Serial.print(“.”);
if (innerLapMilliseconds < 100) {
Serial.print(“0”);
}
if (innerLapMilliseconds < 10) {
Serial.print(“0”);
}
String decimalPoint = “.”;
Serial.println(innerLapMilliseconds);
doc[“innerCounter”] = String(counterInner);
doc[“outerCounter”] = String(counterOuter);
doc[“innerLapTime”] = lapSeconds + decimalPoint + innerLapMilliseconds; <— Here decimals leading zero is lost
serializeJsonPretty(doc, json);
notifyClients(json);
Your help will be appreciated!
Thanks!