Hi All
I'm having trouble with sprintf and I suspect my formatting is incorrect
I'm using a Mega 2560
So I have this function
String Create_Int32_to_String(int32_t Num) {
char buffer[15];
for (uint8_t i = 0; i < 15; i++) {
buffer[i] = "";
}
int32_t Top_Part = abs(Num) / 10000;
int32_t Lower_Part = abs(Num) % 10000;
Serial.print("Top Part : ");
Serial.print(Top_Part);
Serial.print(" Lower Part : ");
Serial.println(Lower_Part);
sprintf(buffer, "%s%d.%04ld", Num < 0 ? "-" : "", Top_Part, Lower_Part);
return String(buffer);
}
I can confirm that the Top Part & Lower Part report the correct values (via serial monitor)
However the sprintf returns the wrong values
for example - with the int32_t set as -344397 it should return -34.4397 but it returns -34.323551232
To give context, the result of the function is used as - LCD_4_Line.print(Create_Int32_to_String(GPS_Display_Data.Original_latitude));
As always any help given will be very much appreciated and if someone can show me a better way to do this even better
Kind Regards Grant Brown
