airgradienthq / arduino

Other
207 stars 110 forks source link

`round2` support negative value #209

Closed pnt325 closed 1 month ago

pnt325 commented 1 month ago

Update round 2 decimal digit value on JSON support negative value

airgradienthq commented 1 month ago

@pnt325 Can you please explain the exact purpose of this code change.

pnt325 commented 1 month ago

@pnt325 Can you please explain the exact purpose of this code change.

I use round2 to limit the number of character for double value on JSON. Example value = 12.3456789 add to json it's look like

{
"value": 123.456789
}

after round

{
"value": 123.46
}

It's reduce the data size of JSON. From current code it's just round correct for negative value https://github.com/airgradienthq/arduino/blob/e46e11c03066a4aba3706b90f9184582c1c94178/src/AirGradient.cpp#L45-L46

if the input value is negative the round value is not correct. This update to correct round negative value like I'm mention to link on description.