SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By fireblade
#5707
I need to write float numbers in the LCD, so I need to convert the numbers to a string to write it on LCD. I wonder if anyone knows if there is a function like ftoa or gcvt that work in IAR, to do that conversion. Thanks in advance.
By doragasu
#5708
I've never used MSP devices, but I always use sprintf for conversions to ascii.
By fireblade
#5729
I used sprintf and for example, if I use a float number=1.25, the number in the string appears 1.250000 (always with 6 digits after the decimal point). How can I solve this? Thanks.
By doragasu
#5734
Try this:
Code: Select all
sprintf(buffer, "%.2f", number);
the number after the '.' character specifies the number of decimal digits you want. If you want more (or less) than 2, just change it. Optionally if want to left align the resulting string you can use this:
Code: Select all
sprintf(buffer, "%-6.2f", number);
You can also use '0' instead of '-' to left align filling with zeros instead of blanks. And there are a lot more options! Printf functions are very powerful, I suggest you to have a look to the function help.