Float precision

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
FordPeterson
Posts: 9
Joined: 23 May 2011 21:45

Float precision

#1 Post by FordPeterson » 09 Jun 2011 03:52

I beg your patience. I'm new to MikroBasic and I am trying to figure out why this happens...

dim field1 as float
dim field2 as float

dim txt1 as char(25)
dim txt2 as char(25)

field1 = 146.400
field2 = 0.600

FloatToStr(field1,txt1)
FloatToStr(field2+field1,txt2)

Sending txt1 and txt2 to the LCD it comes out as 146.39999 for txt1 and 146.99998 as txt2.

It appears that each variable slips a digit so the sum is off by 2. Can somebody explain this phenomena?

Thanks

Ford

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: Float precision

#2 Post by slavisa.zlatanovic » 09 Jun 2011 12:06

Hi!

I can confirm that this is not the bug in the FloatToStr routine but a normal behavior when
working with floats.
Best regards
Slavisa

Post Reply

Return to “mikroBasic PRO for AVR General”