2021-02-07 10:12 PM
I want to display floating point number on 8digit 7segment display MAX7219 so i want to convert float value in to char buffer using sprintf() but it not gives exact output
True Studio STM32F103
void display_charDigit(float Value){
char buffer[8];
sprintf(buffer,"%2.3f",Value);
for (uint8_t digit = 6; digit > 0; digit--) {
write_char((7-digit),buffer[6-digit],false);
}
}
while(){
display_charDigit(12.345);
}
2021-02-07 10:56 PM
Also use snprintf() instead. And you don't have to count backwards to write those characters.
2021-02-07 11:32 PM
> sprintf(buffer,"%2.3f",Value);
It seems you did not understand the printf() format string rules.
The width field defines the overall length, not an integral part. Akin to "%8.3f".
Your string is incorrect, as the precision field is defined larger than the overall length.
> display_charDigit(12.345);
As a side note, this is not a float number.