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[16];
unsigned long speed;
unsigned long distance;
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.