Re: avoid scientific notation
- From: "Gerald Hernandez" <Cablewizard@spam_remove@Yahoo.com>
- Date: Tue, 7 Jun 2005 09:36:51 -0600
"Tom F" <TomF@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ED6ABDF2-E8F0-412C-B9C6-2068EC6C4F8B@xxxxxxxxxxxxxxxx
> I am trying to add some large numbers (between 10^15 and 10^300) and want
to
> know the exact values. When VB starts adding the values at that range it
> defaults to using scientific notation. The only solution I've come up with
is
> to save the numbers as strings, have VB add each digit, and dump that into
> another string. That works but is slow and resource intensive. To test it
I
> calculated 2^x up to x=7000. It took a 2ghz laptop about an hour to get
that
> far using that technique and it is only 2108 digits.
>
> Anyway, my question is: Is there a way to tell VB to format to standard
> notation?
Even with the Format$ you are kind of out of luck.
You say you want to know the "exact" values. This just isn't going to happen
with Double precision floating point math.
While your overall numeric range "appears" to be +-4.xx E324, in your case
you are more worried about significant digits. Doubles can only represent a
reasonable approximation to about 15 digits. This is fine for holding a
single value, but when you perform math, the values need to be fairly close
together. Otherwise, your result is only as accurate as your least precise
value.
So in your case, this means that 10^15 + 10^300 = 10^300, which is clearly
not exact. Relatively speaking, the 10^15 is so tiny that it is simply
discarded.
In general, when VB switches to scientific notation it is showing you the
level of precision of the answer. All those values after the E have been
discarded.
The only way you are going to be able to deal with such disparate values is
to use a separate math library designed to handle such extraordinarily large
values / differences, or write your own. I can't think of any in particular
at the moment, but they are out there. And I'm fairly certain they are more
efficient than what you have done so far. But no way around it, to do this
is very resource intensive.
Gerald
.
- Follow-Ups:
- Re: avoid scientific notation
- From: Duane Bozarth
- Re: avoid scientific notation
- References:
- avoid scientific notation
- From: Tom F
- avoid scientific notation
- Prev by Date: RE: avoid scientific notation
- Next by Date: Re: Option Button Problem
- Previous by thread: Re: avoid scientific notation
- Next by thread: Re: avoid scientific notation
- Index(es):