Go Down

Topic: kph to mph (Read 504 times) previous topic - next topic

Pavilion1984

hi all, a little help needed.

kph / 1.609 = mph so i have seen on the internet but i don't know how i would do this in arduino. do i have to use a float?

thanks.

michael_x

As you ask, the answer is "Yes".

However, to work with long, you could easily multiply by 10000L, add 5 for perfect rounding, and then divide by 16090
to get mph from a km/h value.

int mph = (int)((kph * 10000L + 5)/ 16090);
BTW: rounding assumes you work with positive values.

Pavilion1984

thank you michael_x, i will give that a try and yes it's positive numbers.

thanks.

Graynomad

Just work with metres instead of kilometres (ie everything 1000x larger) and format accordingly for display.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Pavilion1984

the value am reading is kph via a cars obd and i can't change that.

Go Up