Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / March 2004



Tip: Looking for answers? Try searching our database.

Numbers Converted to String (changing format)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jansen Barbara - 06 Mar 2004 23:39 GMT
I have the following problem. I have two double value numbers which
need to be multiplied. The answer is returned in +E25 format but I
need the answer to be a complete number since it will go out to a
file. Tried assigning the variable as string but i am having same
issue!

Regards
Jansen
Duane Bozarth - 07 Mar 2004 00:36 GMT
> I have the following problem. I have two double value numbers which
> need to be multiplied. The answer is returned in +E25 format but I
> need the answer to be a complete number since it will go out to a
> file.

What does that have to do w/anything?  You really want a number printed
w/something on the order of 15 values and another 25 zeros following?
What in the world for?

> ....Tried assigning the variable as string but i am having same
> issue!

But, if you're adamant--

a#=sqr(2)*1E13
?a#
14142135623731
b#=sqr(3)*1E12
?b#
1732050807568.88
?a#*b#
2.44948974278318E+25
?format$(a#*b#,"###,###,###,###,###,###,###,###,###")
24,494,897,427,831,800,000,000,000
Rick Rothstein - 07 Mar 2004 09:26 GMT
> > I have the following problem. I have two double value numbers which
> > need to be multiplied. The answer is returned in +E25 format but I
[quoted text clipped - 20 lines]
> ?format$(a#*b#,"###,###,###,###,###,###,###,###,###")
> 24,494,897,427,831,800,000,000,000

Two points about your post. First, you don't need all the number-symbols (#)
in the format statement to force the thousands separator to be printed
throughout the answer. This would have sufficed

    Print Format$(a# * b#, "#,###")

Second, why not eliminate the E-notation and give an answer that is accurate
to 25 places (maximum of 29 places if there is no decimal point)?

    Print Format$(CDec(a#) * b#, "#,###")

That will print out this value...

    24,494,897,427,831,905,014,545,091

Rick - MVP
Duane Bozarth - 07 Mar 2004 14:00 GMT
> > > I have the following problem. I have two double value numbers which
> > > need to be multiplied. The answer is returned in +E25 format but I
[quoted text clipped - 35 lines]
>
>      24,494,897,427,831,905,014,545,091

A) I was just showing that Format$() will do what OP wanted--I did the
"long form" on purpose because it seemed so silly to me to print a
number to that many digits, anyway....

B)
B1) Because OP said he had a Double and there is only 15-16 digits of
accuracy anyway--the remaining are noise.

B2) Because in my example there already is roundoff in a# and b# since
they were forced to Double so again the remaining digits are noise.
Duane Bozarth - 07 Mar 2004 15:22 GMT
> > > > I have the following problem. I have two double value numbers which
> > > > need to be multiplied. The answer is returned in +E25 format but I
[quoted text clipped - 46 lines]
>  B2) Because in my example there already is roundoff in a# and b# since
> they were forced to Double so again the remaining digits are noise.

C) I didn't think of it... :)
Rick Rothstein - 07 Mar 2004 16:15 GMT
> > > > > I have the following problem. I have two double value numbers which
> > > > > need to be multiplied. The answer is returned in +E25 format but I
[quoted text clipped - 48 lines]
>
> C) I didn't think of it... :)

LOL

Rick
jimbo - 07 Mar 2004 00:41 GMT
What code are you using?

>I have the following problem. I have two double value numbers which
>need to be multiplied. The answer is returned in +E25 format but I
[quoted text clipped - 4 lines]
>Regards
>Jansen
Jansen Barbara - 07 Mar 2004 09:53 GMT
I know that it might be strange but required that 0s to be displayed
however I think I found another solution! In vb I can read the string
for E and then read how many 0's to be included.

Thanks
Jansen
> I have the following problem. I have two double value numbers which
> need to be multiplied. The answer is returned in +E25 format but I
[quoted text clipped - 4 lines]
> Regards
> Jansen
Rick Rothstein - 07 Mar 2004 16:00 GMT
The number after the "E" is not the number of 0's in the number; rather, it
is the number of decimal places to move the decimal point. Depending on the
number, it may take you past the end of the last digit or not. For example,

    A = 1.23456789E5

will have no 0's when expanded (the value is 123456.789). If you want to do
it as Strings along the lines of what you suggested, then your code would
look something like this

Number = 1.23456789E25
NumAsString = CStr(Number)
Power = Mid$(NumAsString, InStr(NumAsString, "E") + 1)
Adjusted = Left$(NumAsString, InStr(NumAsString, "E") - 1)
Answer = Left$(Replace$(Adjusted, ".", "") & _
                         String$(Power, "0"), Power + 1)

However, this code wouldn't work if the power wasn't large enough to produce
zeroes at the end (as in the initial example above). If your numbers are
coming from calculations and if the number following the "E" (in the number
resulting from the calculation) is not greater than 28, it is possible to
get all of the digits (depending on "significant digits" considerations)
using the Decimal data type. For example,

    A =123456789012345
    B = 98765432109
    Product = A * B

If you now printed Product out, this is what you get

    1.21932631135939E+25

However, if you did this for the Product calculation

    Product = CDec(A) * B

and printed it out, this is what you get

    12193263113593897260385605

Rick - MVP

then

> I know that it might be strange but required that 0s to be displayed
> however I think I found another solution! In vb I can read the string
[quoted text clipped - 10 lines]
> > Regards
> > Jansen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.