Author 
Message 

vic9317
Newbie
Joined: 16 Nov 2008 Posts: 26

Posted: 19 Feb 2011 11:55:26 pm Post subject: 


Aside from the traditional 1+int(log(abs(X))) trick, are there any other ways to check the length of a Real variable?
Here's the problem:
I want to truncate a number so that it will always have 6 digits. For example, 1.234567 would be truncated to 1.23457, while 12.34567 would be truncated to 12.3457, 123.4567 to 123.457, etc.
I'm able to use the round( command for this, such that I could do round(X,5int(log(abs(X. This method seems to work with fair results, except for its major weakness, when X=0.
I'd like to avoid converting the number into a string and then using length( on it.
So... any ideas? Thanks in advance. 

Back to top 


montytyper
Newbie
Joined: 06 Nov 2010 Posts: 13

Posted: 20 Feb 2011 01:07:34 am Post subject: 


Round(x,5 isn't acceptable? I can't imagine why you would need a number to always be a specific length unless you were using it for some sort of string application. Also, why are strings unacceptable? 

Back to top 


vic9317
Newbie
Joined: 16 Nov 2008 Posts: 26

Posted: 20 Feb 2011 10:14:05 am Post subject: 


Qwerty.55 wrote:
Round(x,5 isn't acceptable? I can't imagine why you would need a number to always be a specific length unless you were using it for some sort of string application. Also, why are strings unacceptable?
I'm using the graph screen to display columns of fixed length, and each column can only fit about six digits' worth. Any more than six digits and the output of the data will overflow into the next column. (I originally had round(X,5), but once X = something like 10.12345, it becomes a problem.)
Converting the number to a string seems rather tedious for such a simple matter (not to mention it'll like slow down the code quite a bit, since I need to do this in a loop). Essentially, I'm using Text(R,C,round(X,5int(log(abs(X, but of course, it won't work when X = 0. 

Back to top 


Deep Thought
Advanced Newbie
Joined: 09 Jun 2009 Posts: 59

Posted: 22 Feb 2011 09:24:48 am Post subject: 


Try Text(R,C,round(X,5int(log(abs(Xnot(X. 

Back to top 


vic9317
Newbie
Joined: 16 Nov 2008 Posts: 26

Posted: 22 Feb 2011 11:36:23 am Post subject: 


Deep Thought wrote:
Try Text(R,C,round(X,5int(log(abs(Xnot(X.
No dice; still would give Err:Domain when X = 0 (since 0*1=0) and, actually, when X ≠ 0 (since X*0=0).
However, Text(R,C,round(X,5int(log(abs(X+not(X seems to work well. I've yet to try other cases other than X = 0 or X ≠ 0 (what other could there be?), but it looks good for now. Well, I suppose the only other exception is if X has an integer part with length of digits > 6, but I suppose I won't encounter too many of those.
Thanks for the suggestion! 

Back to top 


Xeda112358
Active Member
Joined: 19 May 2009 Posts: 520

Posted: 22 Feb 2011 11:38:52 am Post subject: 


Deep Thought wrote:
Try Text(R,C,round(X,5int(log(abs(Xnot(X.
You will want to do Text(R,C,round(X,5int(log(abs(X+not(X so that X=0 will work.
EDIT: Ya ninja'd me
I don't know if this could be useful, but to grab the first 6 digits of a number (regardless of where the decimal is) you can do int(Ans10^(5int(log(Ans+not(Ans Pretty much, 19.66453 will make 196645 as does 196645300.7 or whatever. That just displays the first six digits of the number regardless of whether it is before or after the decimal
Last edited by Guest on 22 Feb 2011 11:41:53 am; edited 1 time in total 

Back to top 


Deep Thought
Advanced Newbie
Joined: 09 Jun 2009 Posts: 59

Posted: 22 Feb 2011 03:50:33 pm Post subject: 


Whoops, fail'd there. . 

Back to top 


