Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

dspic 33ep512mu814 float is getting -.01 reduced

Status
Not open for further replies.

raman00084

Full Member level 6
Joined
Nov 29, 2010
Messages
362
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
4,006
fstr="100.12";
fvalue = atof(fstr);

lcd_gotoxy(1, 2);
printf(lcd_putc, "fstr: %s", fstr); the value pinted is 100.12
lcd_gotoxy(1, 3);
printf(lcd_putc, "fvalue: %f", fvalue); the value printed is 100.11

0.01 is minis ed if i use atof function this is constant for all values i checked for 10 different values the result is same 0.01 is getting reduced

kindly help
kalyan
 

Hi,

Maybe you need some rounding function.

I'm jus guessing...
Because even a float has limited resolution, it can be that "100.12" is safed as "100.119",
Then if only the last digit is truncated the result is "100.11".

Could this be?

Klaus
 

Presume that printf("%f", ) rounds the float value towards zero instead towards the nearest decimal value. To correct the rounding behaviour, you'll need to add a sign dependant offset.

There's an option in ANSI C to select the rounding behviour with a float.h defined constant, but it isn't implemented in many embedded C compilers.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top