Go Down

Topic: How to round a number or float to integer. (Read 6928 times) previous topic - next topic

Marsheng

pow(XX,YY) creates a float.

How do I convert it back to integer ?

Thanks

Groove

Assign it to an integer type, but this truncates.
If you want rounding, add a half first.
Per Arduino ad Astra

Marsheng

I was using

Serial.print(pow(val,3));  and wanted and integer but found this workaround.

Serial.print(pow(val,3),0);          



Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy