Results 1 to 9 of 9

Thread: Double & Single

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Double & Single

    Can someone explain these 2 variable types to me please. integers & longs i understand but these 2 i'm not sure about.

    I dim dbDub as Double and i set its value to 111,111,111,111,111 and it = 111billion,111million,111thousond,111. But when i add 1 more 1 it all of a sudden = 1.11111111111111E+15.

    Now what does this mean? does it mean i now have 1.1 as a value or do i have 1 trillion,111billion,etc....

    What is the difference in speed as compared to Longs and Integers?

    Would i only use Doubles and Singles when i need to use decimal places?

    Thanks!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Double is to Single as Long is to Integer.

    Double and Single are both floating-point variables. The double can hold numbers twice as big. If you make them sufficiently large, they start displaying in scientific notation, and I think you may lose a small amount of accuracy.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  3. #3
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    I believe

    1.11111111111111E+15.


    means
    1.11111111111111 * 10^15

  4. #4
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    That's scientific notation alright...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  5. #5
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    If you would like some technical information about this, click here. But be warned, it's quite complex

    Double precision floats have an accuracy of 15 decimals, so if you have larger numbers (or if you have more than 15 decimals, before and after the comma), doubles will never exactly hold the value you intended to.
    Single precision floats only have an accuracy of 7 decimals. In most cases this is sufficient.

    Calculations with longs and ints are pretty much faster. So, if you're introducing a floating point value, consider if you really need it. Many times the usage of a float can be simulated by multiplying with another integer number. (For example money: $0.15 is also equal to 15 cents.)

    If you have any more questions, just ask them. Good luck

  6. #6

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Thaks alot riis for the tutorial and explination.. It helped alot.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  7. #7
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Originally posted by riis
    Double precision floats have an accuracy of 15 decimals, so if you have larger numbers (or if you have more than 15 decimals, before and after the comma), doubles will never exactly hold the value you intended to.
    Single precision floats only have an accuracy of 7 decimals. In most cases this is sufficient.
    Just to set this straight.. a single is accurate to 7 places and not to 7 places after the decimal point and so it is not sufficient in most any cases that add monetary values eg accounting software, business etc
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim lVar As Single
    3.     Dim lVar2 As Single
    4.    
    5.     lVar = 23456.78
    6.     lVar2 = 33456.31
    7.     Debug.Print lVar + lVar2 '56913.09
    8.  
    9.     lVar = 123456.78
    10.     lVar2 = 133456.31
    11.     Debug.Print lVar + lVar2 '256913.1
    12.  
    13.     lVar = 1023456.78
    14.     lVar2 = 1033456.31
    15.     Debug.Print lVar + lVar2 '2056913
    16.  
    17.     lVar = 51023456.78
    18.     lVar2 = 51033456.31
    19.     Debug.Print lVar + lVar2 '1.020569E+08
    20. End Sub
    Hence the scientific notation that comes in after 7 places are used up.
    Regards
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  8. #8
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Originally posted by rjlohan
    Double is to Single as Long is to Integer.

    Double and Single are both floating-point variables. The double can hold numbers twice as big. If you make them sufficiently large, they start displaying in scientific notation, and I think you may lose a small amount of accuracy.
    Spreading false information are we?
    1.79769313486231E+308 is one hell of a lot more than twice as large as 3.402823E+38.
    You just proved that sig advertisements work.

  9. #9
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Originally posted by nishantp
    Spreading false information are we?
    1.79769313486231E+308 is one hell of a lot more than twice as large as 3.402823E+38.
    I didn't mean it like that. I was referring to the level of accuracy, and the number of bits for the storage of the number really...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

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