BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Tue Jul 17, 2018 6:36 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: how to display to x decimal places
PostPosted: Tue Jan 14, 2014 3:18 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Hi all, i am trying to work out how to display to x number of decimal places on the line below

Code:
LCDWRITE  p8\p1\p7\p6\p5\p4,p2, [lcdclear,homelcd, "Temperature = ", SCRRAM+40, real convert, " deg C"]


This is what i know. After real convert, if i put \1 or \2 or \3 etc... it will display to that amount of decimal places. If i put a \0 the lcd screen fills up with 0's, if i leave blank obviously i get the full figure.
How do i get it to display no decimal places, 20 instead of 20.0?
Also how do i get the decimal point to stay in one place as the figure changes from 1 to 2 digits, eg: 9 - 10?
Thanks


Top
 Profile  
 
 Post subject: Re: how to display to x decimal places
PostPosted: Tue Jan 14, 2014 4:33 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Probably an easy way is to convert what you are trying to output using the DEC modifier instead of the Real modifier

Might have to convert it first? Something like: DEC TOINT convert


Top
 Profile  
 
 Post subject: Re: how to display to x decimal places
PostPosted: Tue Jan 14, 2014 6:20 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
thanks for the reply
i tried this expecting to see the digits of the 12bit register
Code:
convert = toint centigrade
LCDWRITE p0\p1\p7\p6\p5\p4,p2,[scr,scrram+64,"Temp= ",DEC convert DIG 9,DEC convert DIG 8,DEC convert DIG 7,DEC convert DIG 6,DEC convert DIG 5,DEC convert DIG 4,DEC convert DIG 3,DEC convert DIG 2,DEC convert DIG 1]

but all i got was a load of 0's
thoughts?


Top
 Profile  
 
 Post subject: Re: how to display to x decimal places
PostPosted: Tue Jan 14, 2014 6:44 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
Do it in this way


dec toint(convert)


Top
 Profile  
 
 Post subject: Re: how to display to x decimal places
PostPosted: Wed Jan 15, 2014 11:55 am 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
What about the question of how do i get the decimal point to stay in one place as the figure changes from 1 to 2 digits, eg: 9 - 10?
Issue is if i put it at the end of the lcd sometimes it disappears off screen, if i bring it on, the decimal point shifts around.
thanks


Top
 Profile  
 
 Post subject: Re: how to display to x decimal places
PostPosted: Wed Jan 15, 2014 3:56 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Again I am totally rusty, so you might have to experiment.

First you can try using the min/max settings for an output modifier like DEC
DEC2 myval\2

The \2 says the minimal number of characters to output.

However I don't remember if this will output leading 0's or blanks. My guess is it will output 08 09 10

Which may work for you or may not. If Not,

Then you can do it your self: That is you can do something like:
if val < 10 then
lcdwrite ...
else
lcdwrite ...
endif

where in the case of < 10, you may either have to add a blank output or position the cursor one character to the right...


Top
 Profile  
 
 Post subject: Re: how to display to x decimal places
PostPosted: Wed Jan 15, 2014 5:50 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
To confirm, the DEC# tells the maximum characters to display and the \# tells the minimum. Leading 0s will be padded if necessary.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO