View previous topic :: View next topic |
Author |
Message |
waseem
Joined: 05 Jul 2004 Posts: 1
|
Printf & floating numbers |
Posted: Mon Jul 05, 2004 2:12 am |
|
|
Hi!
Whenever i try to send a floating point number to an lcd usin printf function then someting strange happens.e.g if i send 2.30 then the number that is actually displayed is 2.29, similarly if i send 2.00 then the number 1.99 is displayed. What might be causing this?
_________________ "Planet Earth, a place for peacelovers" |
|
|
Paolino
Joined: 19 Jan 2004 Posts: 42
|
|
Posted: Mon Jul 05, 2004 2:41 am |
|
|
Which compiler version are you using? Which PIC? Can you post a little bit of code, please?
Paolo. |
|
|
Guest
|
Re: Printf & floating numbers |
Posted: Mon Jul 05, 2004 3:36 am |
|
|
waseem wrote: | Hi!
Whenever i try to send a floating point number to an lcd usin printf function then someting strange happens.e.g if i send 2.30 then the number that is actually displayed is 2.29, similarly if i send 2.00 then the number 1.99 is displayed. What might be causing this?
|
nothing wrong but simple truncation
there are no such thing as 2.3000000 in PIC, what stored in PIC memory is actuall something like 2.299999, because CCS float only use 32 bit, the accuracy is around 1.2e-7, try this then you will see some more digits
float x = 2.3;
printf("%f", x) |
|
|
|