Page 1 of 1

how to print a decimal value in lcd

Posted: Sun Apr 15, 2012 3:10 pm
by rags
hello sir,

what function should i use to print a decimal value
for eg a=7
b=2
c=a/b and in lcd when i use print number(c) command i want the lcd display to show 3.5 but float is not supported pls help


regards
ragesh

Re: how to print a decimal value in lcd

Posted: Sun Apr 15, 2012 3:25 pm
by medelec35
Hi ragesh,
I have moved topic so we can keep Tips section for posting tips, and not starting topic with a question question.

As for the Decimal point, take a look here:
http://www.matrixmultimedia.com/mmforum ... 326#p20298
There are two replies that should be able to help you.

With your example, I would 1st multiply a by 10 so you have got 70/2

Reason for that is with pic maths if not using float it will disreguard any remainders since bytes and intergers are whole numbers only.
so 7/2 = 3
not 3.5

Martin

Re: how to print a decimal value in lcd

Posted: Sun Apr 15, 2012 3:30 pm
by rags
hello sir,
as i am using flowcode for AVR can u please guide to a topic that deals my question with AVR
thank you!!

Re: how to print a decimal value in lcd

Posted: Sun Apr 15, 2012 3:39 pm
by medelec35
You will be able to use import function from File/ Import to import pic versions of Flowcode.

Or do you mean you want this thread moved to Flowcode V4?

What version of AVR do you have (Help, About Flowcode menu)?

If the version is too early then you will not be able to import successfully.

Re: how to print a decimal value in lcd

Posted: Sun Apr 15, 2012 3:42 pm
by rags
sir,

i use flowcode v4..i have imported it..but i want to display a mathematical calculation in decimals not an ADC value..
say 7/2..i want 3.5 to be displayed in my LCD display

Re: how to print a decimal value in lcd

Posted: Sun Apr 15, 2012 4:28 pm
by medelec35
Instead of adc, your using your own variables.
That flowchart was to show you a method of how it can be done, then you just create your own flowchart once you have learned the principles.

For that method you need to learn how Left$ and Right$ work.

Then as stated in my previous post
medelec35 wrote:
With your example, I would 1st multiply a by 10 so you have got 70/2

Reason for that is with pic maths if not using float it will disreguard any remainders since bytes and intergers are whole numbers only.
so 7/2 = 3
not 3.5


So 70/2=35
Convert to string then use Left$ and Right$ to separate the two digits.

Alternatively you can use the Mod function to separate the digits.
e.g

Code: Select all

Digit_0 = Voltage MOD 10
Digit_1 = Voltage / 10 MOD 10 
If your still stuck then I can post a flowchart to demonstrate both methods.
See if you can have a go first and post a flowchart, as that is a good learning method.

Martin

Re: how to print a decimal value in lcd

Posted: Mon Apr 16, 2012 11:07 am
by medelec35
Hi rags,
I have altered flowchart from link I had posted, to display the result with a decimal point.
It may not be perfect, but it should do what you’re after.
a div b v1.fcf
(8.5 KiB) Downloaded 482 times
Martin

Re: how to print a decimal value in lcd

Posted: Wed Apr 18, 2012 4:46 pm
by rags
hello sir ,
thanks for your response , thanks a lot!

i tried and have come up with a better and very easy solution.
what i did was..
a=7
b=2
c=7/2

all variables are FLOAT,
initialze string variable str. then use string manuplation[ str=floattostring(c)] ; now in lcd print string--> str and the its accuracy is upto six decimals!
thank you,

reagrds
ragesh

Re: how to print a decimal value in lcd

Posted: Wed Apr 18, 2012 4:47 pm
by rags
sorry small typing mistake in previous post

it is c=a/b

and its NOT
c=7/2

Re: how to print a decimal value in lcd

Posted: Wed Apr 18, 2012 5:09 pm
by rags
i have attched a sample file.
i have used at,ega32 MCU