# dot . on numbers

Hello everyone. I make some calculations on my arduino. Like the distance and speed. I get correct anwsers but I cant find a way to put the .(dot) on my calculations. For example i have 157m instead of 15.7 or 11km/h instead of 1.1km/h

Here is my code:

char buf;
unsigned long speed;
unsigned long distance;

speed = gps.speed();
if (speed > 1000) speed = 0;
sprintf(buf, "SPEED:%d km/h ", (int)(distance / 30));

long distance = sqrt((lat - originLat) * (lat - originLat) + (lon - originLon) * (lon - originLon));
sprintf(buf, "DST: %ld m ", distance);

how can i put the . on my answers?

Thank you.

type long (signed or unsigned) is an integer. Use type float or double.

Note that the arduino's sprintf does not support floating point for code size reasons. You'll need something such as dtostrf to produce your strings.

I didnt find a way to put a dot. I found another example of someone that he put a dot on latitude or longitude with this way:

"LAT:%d.%05ld",

and on the lcd is displayed like 123.12345

well i want to display for example 157. How do I put the dot to be 15.7 with this way?
i guess it is like %d.%01d?? But it shows me wrong calculations

We call the dot a decimal point.

If you are starting with an integer, you can reduce it to two integer variables like this:

int value = 157;
int tens = value/10; //15
int units = value%10; //7

then print the two variables tens and units in one statement, using the format string "%d.%01d" and you will get 15.7
This will work properly only for positive numbers.