Page 1 of 1

Decimal Point in LCD

Posted: Fri Feb 04, 2011 4:55 pm
by iain wilkie
Bit stuck here ! .... I have an INT variable ... it can only be 0 to 9999, but I want to display it as 0.000 to 9.999
How do I output it to the LCD in this format ?

Re: Decimal Point in LCD

Posted: Fri Feb 04, 2011 6:00 pm
by JohnCrow
One easy way is to convert the interger to a string
Split using left$ and right $
Print string onthe LCD Int part, print a "." then print the decimal

Ive attached a very simple exmple of how to manipulate strings.

I suppose the other way would be to convert to a float and then divide by 10 or 100 ect .
But then you would still have to convert float to string to display on the lcd

Hope this helps

Re: Decimal Point in LCD

Posted: Fri Feb 04, 2011 6:29 pm
by iain wilkie
That works fine for numbers like 1234 but a nuber like 55 needs to display as 0.055 ....

Iain

Re: Decimal Point in LCD

Posted: Fri Feb 04, 2011 6:50 pm
by Dan81
Hello Iain

In a calculation :

TH = N DIV 1000
var = N MOD 1000
HND = var DIV 100
var = var MOD 100
TEN = var DIV 10
UNT = var MOD 10

then

PRINT_NUMBER (TH)
PRINT_ASCII (',')
PRINT_NUMBER (HND)
PRINT_NUMBER (TEN)
PRINT_NUMBER (UNT)



Daniel

Re: Decimal Point in LCD

Posted: Fri Feb 04, 2011 6:58 pm
by iain wilkie
Thanks guys ... found another solution,

The max value is 9999 so all I do is add 10000 to the value so I know it will always be 5 digits.
Then int = mid$(val,1,1)
and dec = right$(val,3)

Then just output to lcd int "." dec

Cheers