Your x-int(x) idea would work if floating-point numbers did not
sometimes stray slightly from exact. You could still use that
approach, but you would then have to round the result, which would
require you to know the number of decimal places you want in the first
place. That would probably require string manipulation, which would in
turn force you to get locale information anyway. You might try
rounding to the largest number of decimal places you should ever need
if that's practical, but otherwise I suspect you'll end up preferring a
string-based solution here.
On Tue, Jan 01, 2013 at 03:27:10PM +0100, David wrote:
I have been playing for a while now, with a tricky numeric issue.
Hopefully, it is just that I have overlooked some kind of instruction.
What I am trying to do, is to derive the decimals, from a floating
point number.
Let's for instance say, you have the number:
123.4567890
I know, you can use the Int Or CInt instructions on this number, and it
will return 123. That is, the digits to the left of the decimal point.
But what I am after, is a way to have returned the digits to the right
of the decimal point - in the example above, that would give 4567890. I
really can't seem to find an instruction that will let me do this. Or,
maybe it is named somthing, that my English knowledge would not have
included. Smile. So if anyone out there, would happen to know of such
an instruction or workarounds for this task, I would greatly appreciate
your feedback.
OK, You would think, that if we did a basic piece of math, things
should not get too complicated. So I thought, if I take my original
number, and subtract the Int value of the number, I would end up with a
simple decimal number, that I then could do some extra work on. Well, I
tried a code like this:
X = 123.4567890
speak x -int(x)
. What I did expect, was to get the return value of "0.4567890". But,
that's not what I get. My script will speak out the number of
0.456789000000001
. and if you do a more direct way, like:
speak 123.4567890 -123
; you might end up with an even less predictable number.
Well, my idea was - for a workaround - to have converted the returned
value into a string, and then simply omitted the first two characters
(which would be 0.). Then, I could have converted the final string back
to a number, and had the job done. Not exactly anything straight
forward, but it would have been a workaround. Yet, long as the returned
value is not as expected, that workaround would not be useful.
Again, is there an instruction in VBS, that will directly return only
the digits to the right of the decimal point?
One more thing. Some of you, might be wondering, why don't I just
convert the original number into a string, and then split by the
decimal point. A code like this:
x = 123.4567890
NumString = Split(X, ".")
Speak NumString(1)
. OK, this would work perfectly; long as we are operating numbers that
follow English standard, with the dot-sign as the decimal point. But in
other languages, the comma-sign is used as a decimal point. Since I
want the script to work, no matter the locale setting of the computer,
and the corresponding decimal point character, I would have been more
satisfied with a direct instruction for deriving the digits to the
right of the decimal point.
Hope all of this makes sense, and that someone could give me a kick in
the right direction for a solution.
--
Doug Lee, Senior Accessibility Programmer
SSB BART Group - Accessibility-on-Demand
mailto:[email protected] http://www.ssbbartgroup.com
"While they were saying among themselves it cannot be done,
it was done." --Helen Keller