How to round to whole number within macro?
-
Is there a way to round a value to a whole number, from within a macro? For example:
sensors.analog[2].lastReading = 123.4 - how to get reading as 123?
sensors.analog[2].lastReading = 123.6 - how to get reading as 124?Thanks much,
Kolbi -
See the floor function, https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands#Section_Functions.
-
@dc42 Thanks!
I'll play around with it when I get out of work.
Could you possibly give me a simple syntax / usage example? -
@Kolbi said in How to round to whole number within macro?:
@dc42 Thanks!
I'll play around with it when I get out of work.
Could you possibly give me a simple syntax / usage example?Look up "floor function". It rounds down (towards minus infinity) to integer. So if you want to round to nearest integer, use:
floor(sensors.analog[2].lastReading + 0.5)
-
@dc42 Thanks so much!