This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using float variable

Hello everyone !

I have a problem with the float variables.

For example, i define float a = 123456123456.1234 and char lcd[30];

I used sprintf function to convert a to string and store into lcd (sprintf(lcd,"%0.2f",a);).

Then, i export lcd to LCD 16x2.

Result i see on the LCD is "123456100000.00"

Why this ?

And can everyone show me how to print a on LCD ("123456123456.1234")?

Best regard !

Parents
  • a lot of people 'automatically' go for float when it is not neded. Especially in small (e.g.'51) processors that is a BIG mistake. For a '51 to process a float it need a LOT of cycles.

    as an example: if all your values have up to two digits after the decimal point process everything as 100 * actual value and just insert the decinmal point in the appropiate place on the display

    Erik

Reply
  • a lot of people 'automatically' go for float when it is not neded. Especially in small (e.g.'51) processors that is a BIG mistake. For a '51 to process a float it need a LOT of cycles.

    as an example: if all your values have up to two digits after the decimal point process everything as 100 * actual value and just insert the decinmal point in the appropiate place on the display

    Erik

Children
No data