An archive of community.esquilo.io as of Saturday January 26, 2019.

Round to second decimal place

JefferyS

Is there anything in squirrel that I can use to round a float (20.34563) to 2 decimal places.

I looked but didn't see anything that I could find to do that.

I'm wanting to round the temperatures I'm getting from my temp sensors.

Thanks,

Jeffery

gwittie

Here is snapshot of what I did...

// Add "string" to the require statement.
tempFra <- 0.0; // wanted temp in degrees F
// Assume sensorC is degrees C value read from sensor
sensorC <- 20.34563;
tempFra = format("%0.2f",((sensorC * 1.8) + 32.0)); // Save in degrees F
print("roomt= "+tempFra+"\n");

JefferyS

That's great, thanks gwittie.

benhaubin

Multiply by 10 ^ [decimal places], round, then divide by 10 ^ [decimal places].