Page 1 of 1

Displaying Float value on LCD

PostPosted: Wed Oct 17, 2012 5:51 am
by potatomashers
Hi guys,
i,m new here and very new in PIC programming... :D

i,m developing a project that calculate currency.
for example: i want to add 10cent,20cent, and 50 cent..

but i just know how to display decimal value only and kinda stuck with float value... :?
can anyone give me guide or example for this kind of code??

i'm using PIC 16F877A with HITECH C compiler.

thanx in advance..

sorry for my bad english..

Re: Displaying Float value on LCD

PostPosted: Wed Oct 17, 2012 8:20 am
by shahrul
I never use float number. If I want use decimal number, I store in integer. Eg, 1.23 saved as 123.
When display
lcd_number(no/100,DEC,1);
lcd_string(".");
lcd_number(no%100,DEC,2);

Re: Displaying Float value on LCD

PostPosted: Wed Oct 17, 2012 11:30 pm
by yonghui
it depends on how many decimal u wan to display. below shows simple conversion for display
for example if u wan to display 111.222

u eliminate the decimal point 1st by converting it to integer

float fnumber=111.222;
int inumber;
inumber= (int) (fnumber);

then for decimal points, multiply the left over after subtract the float number from the int number with the 10 power the number of decimal point
float decimal;
decimal=fnumber-inumber;
decimal=decimal*1000; // for 3 decimal point

int dec_point;

dec_point= int (decimal );

so after this u can display the floating point number by printing both the value with a decimal point at middle of both

printnum(inumber);
printchar('.');
printnumber(dec_point);





or simple way, find a library to print it.

Re: Displaying Float value on LCD

PostPosted: Sat Oct 20, 2012 12:01 am
by potatomashers
PROBLEM SOLVED!!

thanks guys!..i appreciate it...
it really helped me a lot.. :D