Pages: [1]   Go Down
Author Topic: How to round a number or float to integer.  (Read 5209 times)
0 Members and 1 Guest are viewing this topic.
New Zealand
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Motorcycle racing rocks.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

pow(XX,YY) creates a float.

How do I convert it back to integer ?
 
Thanks
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Assign it to an integer type, but this truncates.
If you want rounding, add a half first.
Logged

Per Arduino ad Astra

New Zealand
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Motorcycle racing rocks.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was using

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

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


Logged

Pages: [1]   Go Up
Jump to: