Results 1 to 20 of 20

Thread: Number

  1. #1

    Thread Starter
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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.


  2. #2
    Lively Member ThE_EnGinE's Avatar
    Join Date
    Jun 2006
    Location
    Liverpool, UK
    Posts
    87

    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.

  3. #3

    Thread Starter
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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.


  4. #4
    Lively Member ThE_EnGinE's Avatar
    Join Date
    Jun 2006
    Location
    Liverpool, UK
    Posts
    87

    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.

  5. #5
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    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...

  6. #6

    Thread Starter
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Number

    Quote 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.


  7. #7
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    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...

  8. #8
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    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$.

  9. #9

    Thread Starter
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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.


  10. #10
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: Number

    Quote 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.

  11. #11

    Thread Starter
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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.


  12. #12
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    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

  13. #13
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: Number

    Quote Originally Posted by ganeshmoorthy
    so, what should be used...
    If you have declared it as String you may try this.

    VB Code:
    1. StrTotal = FormatNumber(CDbl(Value 1) + CDbl(Value 2), 22)

    Maybe it will work.

  14. #14
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    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...

  15. #15
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    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

  16. #16

    Thread Starter
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Number

    Quote Originally Posted by tommygrayson
    If you have declared it as String you may try this.
    VB Code:
    1. 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...

    Quote 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.


  17. #17
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: Number

    Here, this works:
    VB Code:
    1. Dim a As Double
    2.   Dim b As Double
    3.   Dim c As Double
    4.  
    5.   a = 85200963741#
    6.   b = 96300852147#
    7.   c = a * b
    8.  
    9.   'displays: 8,204,925,412,003,950,000,000.00
    10.   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

  18. #18

    Thread Starter
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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.


  19. #19
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: Number

    Quote 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.

  20. #20
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    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
  •  



Click Here to Expand Forum to Full Width