Displaying Float value on LCD

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Displaying Float value on LCD

Postby potatomashers » Wed Oct 17, 2012 5:51 am

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..
potatomashers
Greenhorn
 
Posts: 2
Joined: Sun Oct 02, 2011 11:12 pm

Re: Displaying Float value on LCD

Postby shahrul » Wed Oct 17, 2012 8:20 am

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);
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Displaying Float value on LCD

Postby yonghui » Wed Oct 17, 2012 11:30 pm

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.
thanks&regards,
yh
yonghui
Professional
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Displaying Float value on LCD

Postby potatomashers » Sat Oct 20, 2012 12:01 am

PROBLEM SOLVED!!

thanks guys!..i appreciate it...
it really helped me a lot.. :D
potatomashers
Greenhorn
 
Posts: 2
Joined: Sun Oct 02, 2011 11:12 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 0 guests