- // if speed is below one then it's zero
- if(speed < 1) {
- set_nth_digit(appdata, 0, 0);
- set_nth_digit(appdata, 1, 0);
- set_nth_digit(appdata, 2, 0);
- return;
- }
-
- // speed => 1
- // first let's convert the number to string
- gchar* cspeed = g_malloc(30); // alloc
- g_sprintf(cspeed, "%f", speed);
-
- // split the string using comma as delimiter
- gchar** splitted = g_strsplit(cspeed, ",", 2); // alloc
-
- gchar* ckm = splitted[0]; // contains the km/h part e.g 123 assuming speed was 123,034510
- gchar* cm = splitted[1]; // contains the m/h part e.g 034510 assuming speed was 123,034510
+ // convert float to a 6 digits (including dot) wide string with leading zeros
+ gchar* charspeed = g_malloc(10); // alloc
+ g_sprintf(charspeed, "%0*.2f", 6, speed);