|
-
Jun 27th, 2006, 02:05 AM
#1
Number
consider this calculation
Value 1 : 85200963741
Value 2 : 96300852147
Result : 8.20492541200395E+21
but the expected result should be 8204925412003949001927
I think it is converting the double value to something...
any help would be appreciated...
PS: All the variables are declared as double
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jun 27th, 2006, 02:14 AM
#2
Lively Member
Re: Number
The number is far too big. VB can only use numbers that are 18 digits long as the maximum, else it will go into what looks like standard form lol.
Slow Cheetah come before my forest!
Looks like it's on today.
Slow Cheetah come, it's so euphoric!
No matter what they say.
If you have the answer to your question. Click "Thread Tools" and then "Mark Thread Resolved".
If you find a post useful. Rate it by clicking "Rate This Post" on the left of the post.
-
Jun 27th, 2006, 02:19 AM
#3
Re: Number
but windows calculator displays it correclty...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jun 27th, 2006, 02:22 AM
#4
Lively Member
Re: Number
Windows calculator probably isn't made in VB.
Slow Cheetah come before my forest!
Looks like it's on today.
Slow Cheetah come, it's so euphoric!
No matter what they say.
If you have the answer to your question. Click "Thread Tools" and then "Mark Thread Resolved".
If you find a post useful. Rate it by clicking "Rate This Post" on the left of the post.
-
Jun 27th, 2006, 03:10 AM
#5
Hyperactive Member
Re: Number
just sent calc to notepad, and it was made in C++.
can you add some zeros after the decimal?
vb's floating point is only so precise, does the difference matter to you? the discrepancy is tiny, percentage wise.
you might consider using a UDT to segment the calculations...
-
Jun 27th, 2006, 03:39 AM
#6
Re: Number
 Originally Posted by md me
can you add some zeros after the decimal?
vb's floating point is only so precise, does the difference matter to you? the discrepancy is tiny, percentage wise.
could you explain it please...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jun 27th, 2006, 04:03 AM
#7
Hyperactive Member
Re: Number
nevermind, i tried it.
you are apparantly stuck with "only" 16 digits of information
since multiplication is communitive, you could break the initial numbers into smaller components, mulitply those, convert them to a string, and combine them in a string representing the calc output...
like doing 5*5*5 instead of 25*5...
remember, 16 digits of info max...
-
Jun 27th, 2006, 04:31 AM
#8
Hyperactive Member
Re: Number
you might be able to use shell, and an outside command line calculator.
i also know that win2k/xp's SET command allow math operations, though i have no idea of what size limit is imposed. you can retrieve data from a set command using environ$.
-
Jun 27th, 2006, 04:37 AM
#9
Re: Number
thanks a lot md me...i'm actually developing a calculator project, i think the outside command line calculator or shell can be used... any example will be useful...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jun 27th, 2006, 04:42 AM
#10
Hyperactive Member
Re: Number
 Originally Posted by ganeshmoorthy
consider this calculation
Value 1 : 85200963741
Value 2 : 96300852147
Result : 8.20492541200395E+21
but the expected result should be 8204925412003949001927
I think it is converting the double value to something...
any help would be appreciated...
PS: All the variables are declared as double
Why should you use double variables when a string can contain 255 digits.
-
Jun 27th, 2006, 04:49 AM
#11
Re: Number
so, what should be used...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jun 27th, 2006, 04:54 AM
#12
Fanatic Member
Re: Number
String mathematics is an ugly beast. I've written functions to do basic (+, -, *, /) on strings, but it's nasty.
The result displayed by the double is correct. All calculations done on it will be accurate. What you get is just the notation for huge numbers.
r0ach™
Don't forget to rate the post
-
Jun 27th, 2006, 04:55 AM
#13
Hyperactive Member
Re: Number
 Originally Posted by ganeshmoorthy
so, what should be used...
If you have declared it as String you may try this.
VB Code:
StrTotal = FormatNumber(CDbl(Value 1) + CDbl(Value 2), 22)
Maybe it will work.
-
Jun 27th, 2006, 04:56 AM
#14
Hyperactive Member
Re: Number
ok, well i checked, and SET is out, at least for this.
just for reference:
C:\>set /a Result = "85200963741 * 96300852147"
but it returns:
Invalid number. Numbers are limited to 32-bits of precision.
perhaps running a java script on an IE form would do the trick...
-
Jun 27th, 2006, 04:58 AM
#15
Fanatic Member
Re: Number
By the way, the string notation calculates as (using example above):
8.20492541200395 * (10 ^ 21)
r0ach™
Don't forget to rate the post
-
Jun 27th, 2006, 05:02 AM
#16
Re: Number
 Originally Posted by tommygrayson
If you have declared it as String you may try this.
VB Code:
StrTotal = FormatNumber(CDbl(Value 1) + CDbl(Value 2), 22)
for you kind information, please read my post clearly, I already declared the variables as double...
 Originally Posted by r0ach
The result displayed by the double is correct. All calculations done on it will be accurate. What you get is just the notation for huge numbers.
Yes, I know that...but I want to disply the result in normal numbers not in notations....
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jun 27th, 2006, 05:02 AM
#17
Fanatic Member
Re: Number
Here, this works:
VB Code:
Dim a As Double
Dim b As Double
Dim c As Double
a = 85200963741#
b = 96300852147#
c = a * b
'displays: 8,204,925,412,003,950,000,000.00
Debug.Print Format(c, "#,##0.00")
I think it's as accurate as you'll get it with normal vb functions
r0ach™
Don't forget to rate the post
-
Jun 27th, 2006, 05:11 AM
#18
Re: Number
r0ach : If I use the post #17, then
I get
7259204222395200000000.00
instead of
7259204222395196715081
for the calculation 85200963741 * 85200963741
do you think is that ok...
even for the values you have given, the actual result in windows calculator is 8204925412003949001927, but your code will return 8,204,925,412,003,950,000,000.00
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jun 27th, 2006, 05:15 AM
#19
Hyperactive Member
Re: Number
 Originally Posted by ganeshmoorthy
for you kind information, please read my post clearly, I already declared the variables as double...
Yes, I know that...but I want to disply the result in normal numbers not in notations....
Perhaps, you did not understood me.
If you declared your total number to string then the above expression would be appropriate.
You did not say that you would only want to use double variables only.
-
Jun 27th, 2006, 05:17 AM
#20
Fanatic Member
Re: Number
You can specify "###" or 22 like tommygrayson mentioned, but I googled and it appears as though VB is limited to 15 significant digits.
Even MS Excel 2003 gives 7259204222395200000000.00 instead of 7259204222395196715081
Last edited by r0ach; Jun 27th, 2006 at 05:23 AM.
r0ach™
Don't forget to rate the post
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|