 # Working with floats

Hi everyone, I am doing a project for which I wish to obtain some GPS data, and use the speed measured by the GPS device. For that I first want to turn this speed in knots, given in a character array, into a float, in m/s.

I have found a way that works (speedOL is a character array of 4, with value 0.04 for this example)

``````Serial.print(speedOL);
Serial.print(speedOL);
Serial.print(speedOL);
Serial.print(speedOL);
Serial.println("knots");

//speedOL (knots) to velocity (m/s)
float speedOL0 = speedOL-'0';
float speedOL2 = speedOL-'0';
float speedOL3 = speedOL-'0';
float velocitytest= (speedOL0+0.1*speedOL2+0.01*speedOL3)*0.514; //m/s
Serial.print(velocitytest);
Serial.println(" m/s");
``````

with output:

0.04knots
0.02 m/s

exactly what I need.

Now I thought I could make this shorter, and with less variables, by writing:

``````Serial.print(speedOL);
Serial.print(speedOL);
Serial.print(speedOL);
Serial.print(speedOL);
Serial.println("knots");

float velocity = ((speedOL-'0')+(0.1*speedOL-'0')+(0.01*speedOL-'0'))*0.514; //m/s
Serial.print(velocity);
Serial.println(" m/s");
``````

but this has output:

0.04knots
-46.61 m/s

Now I can't really make sense of why the first one works, but the second one does not. Maybe I am missing something, or I am doing something wrong.
All help is appreciated greatly.

How about ?`(0.1 * (speedOL - '0'))`

Deva_Rishi:
``````(0.1 * (speedOL - '0'))
What an obvious mistake! 