Not entirely sure what you mean. I assume that you want to round down, not to nearest value but just limit the nr of decimals?
If so, can use this trick: x = (int)(x * 100) / 100.0
Thank you for taking the time to help.
Can you help a bit more and talk me through how this is working?
My understanding is that (int) turns x into an integer, then it is multiplied by 100, then divided by 100.
Lastly, the integer is “returned” to the sensor - a float. So is this just a “cast”: float > int > float?
This is my full lambda - just in case the context is making a difference!
- lambda: |-
x = (int)(x * 100) / 100.0;
ESP_LOGI("myDiagString", "The value of x is: %.5f", x);
return x;
This indeed will turn 123.456 into 123.45 (two decimal places). But how do I extend this to strip to one (or three) decimal place?
Change the 100’s to 10’s? No. That still results in 123.456 returning 123.45?