How do I display decimal values?
BigMike
Posts: 34
Hello again,
Board: Parallax Board of Education
Chip: BS2px24
Throughout my prototyping of a circuit that is essentially reading resistance values and then outputting decimal calculations based on the readings to a 20x4 LCD screen, I have only been using the DEC command for output just for testing purposes. I am now to the point where I need to begin fine tunning my project, and I must have values outputted to my LCD screen including their decimal values.
For a very simple example, what if I wanted to divide 5 by 4 and then have "1.25" display on my screen instead of simply "1" which is what the DEC does.
As we all know, if I do this:
The output will of course be "1"
Now how can I code it so the output is "1.25"?
I am assuming the Variable type (Word) is wrong and also I should not be using DEC, but what?
I have searched here and also on the net, and this must be something extremely simple because I can't find any help on it anywhere -- sorry for being such a noob! I am learning as I go!
As always, thanks for the help!
BigMike
Post Edited (BigMike) : 3/1/2008 6:27:04 PM GMT
Board: Parallax Board of Education
Chip: BS2px24
Throughout my prototyping of a circuit that is essentially reading resistance values and then outputting decimal calculations based on the readings to a 20x4 LCD screen, I have only been using the DEC command for output just for testing purposes. I am now to the point where I need to begin fine tunning my project, and I must have values outputted to my LCD screen including their decimal values.
For a very simple example, what if I wanted to divide 5 by 4 and then have "1.25" display on my screen instead of simply "1" which is what the DEC does.
As we all know, if I do this:
X VAR Word X = 5/4 DEBUG DEC X
The output will of course be "1"
Now how can I code it so the output is "1.25"?
I am assuming the Variable type (Word) is wrong and also I should not be using DEC, but what?
I have searched here and also on the net, and this must be something extremely simple because I can't find any help on it anywhere -- sorry for being such a noob! I am learning as I go!
As always, thanks for the help!
BigMike
Post Edited (BigMike) : 3/1/2008 6:27:04 PM GMT
Comments
If you scale your numbers so that everything or maybe some values are stored as hundreths rather than as units, then
display them that way, you can do something similar to what you want. There are issues to deal with on adjusting the
scale of values and you have to display the decimal points yourself (since the numbers are still integers internally).
Also, there's only 16 bits to a value which comes out to about 4 1/2 decimal places and you have to account for that.
If you treat X as a value in hundreths, your expression would be X = 500 / 4 which is 125. This could be displayed with
DEBUG DEC x/100, ".", DEC2 x//100 and would show on your LCD as "1.25".
There is some excellent discussion of scaling and multiple precision arithmetic on the Stamp here: www.emesystems.com.
Again, you have come to my aid and I thank you [noparse]:)[/noparse]
Ok, so it was not just me being crazy [noparse];)[/noparse] I can easily scale my numbers and truthfully I am only looking for 1 decimal point (tenths).
And BTW, on my other thread, I still never got the Parallax 16x2 LCD to work with my BS2px24 chip, but I bought and built the 117 Kit and am using a 20x4 LCD screen and I got this LCD screen to work using the baudmode 396
BigMike