Hi Dave,
Try this simple conversion method and see if it works!
Bruce
Example Dim sdbl, dblValue
dblValue = 123.4567890
sdbl = CStr( dblValue)
Replace( sdbl, ".", "")
dblValue = CDbl( sdbl)
Sent: Tuesday, January 01, 2013 10:13 AM
Subject: Re: VBS code - floating point numbers
Thanks Bruce, for your feedback.
Now, the script will receive inputs, and it could never be told how many
decimals will be in the incoming number. The number I gave, was just to
illustrate. One time, you will get the number 3.42, next time 5.4495; and
another time 123.9087654.
The ideas you outlined, will they work? Of course, I could use your approach
(* 1000000.0), but that I guess, would not work if there is only 3 or 4
decimals. And, what if you get a number with 10 decimals. I then would have to
come up with a way to determine how many decimals are in the incoming number,
before I could take your approach - wouldn't I? Or, am I missing your point.
----- Original Message -----
From: BX
To: [email protected]
Sent: Tuesday, January 01, 2013 3:57 PM
Subject: Re: VBS code - floating point numbers
Hi Dave,
You just use the decimal factor, if you want to move it 3 places the
use times 1000.
Now to keep things in the same format make sure use use the decimal
point all the time. Even though VB does not care, too loose in it's numbering
systems.
123.4567890 * 1000000.0
Or a shift left would also do the same thing...
Bruce
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.