Results 1 to 23 of 23

Thread: [RESOLVED] Scientific notation to string

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    472

    Resolved [RESOLVED] Scientific notation to string

    How do I get a huge value (more than 16 digits from double var) into a textbox without it being in scientific notation.

    Val() and CDbl() returns a value like 1.0923772290313E+15 but I need the number without it being in the E+15 format e.g. 109237722903135248725245

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Scientific notation to string

    Try something like this
    Code:
    txtBox.Text = Format(dblValue,"#0.00")
    Where dblValue is your double variable

  3. #3
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Scientific notation to string

    however it returns only 15 digits after that only zeros.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    472

    Re: Scientific notation to string

    So how do I get my formula to return more than 15 digits?

  5. #5

  6. #6
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Scientific notation to string

    this may be useful
    Code:
    Dim i As Long
    Dim x
    x = 1
    For i = 1 To 74
        x = CDec(x * 2)
    Next
    MsgBox x
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Scientific notation to string

    Quote Originally Posted by Bezzie View Post
    So how do I get my formula to return more than 15 digits?
    You can use the CDec() function. Try this:
    Code:
    Debug.Print "Single: "; CSng(1/3)
    Debug.Print "Double: "; CDbl(1/3)
    Debug.Print "Decimal #1: "; CDec(1/3)
    Debug.Print "Decimal #2: "; CDec(1) / CDec(3) ' CDec( 1 / CDec(3)) returns same result
    ' note that to gain max digits, internal parts of calc need to be converted to decimal
    Results look like this:
    Single: 0.3333333
    Double: 0.333333333333333
    Decimal #1: 0.333333333333333
    Decimal #2: 0.3333333333333333333333333333

    Last but not least. To store the result in a variable, use Variant, not Double, not Long:
    Code:
    Dim vDec As Variant
    vDec = CDec(1) / CDec(3)
    Edited: seenu_1st beat me to it.
    Last edited by LaVolpe; Jul 1st, 2011 at 11:04 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    472

    Re: Scientific notation to string

    The number is a whole number, not a decimal number.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Scientific notation to string

    Doesn't matter, logic is the same. Look at the post by seenu_1st for whole number example.

    How many digits are you going to need. Even the CDec() has limits.

    Edited: Here's the max limits per MSDN
    Quote Originally Posted by MSDN
    +/-79,228,162,514,264,337,593,543,950,335 for zero-scaled numbers, that is, numbers with no decimal places.
    For numbers with 28 decimal places, the range is +/-7.9228162514264337593543950335.
    The smallest possible non-zero number is 0.0000000000000000000000000001 (+/-1E-28).
    Last edited by LaVolpe; Jul 1st, 2011 at 11:14 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    472

    Re: Scientific notation to string

    I need 16 digits at the moment but not more than 20.

    Thanks guys. I'm going to look into the suggestions.

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Scientific notation to string

    In my post #5 you can change the '15' to 16 or 20 to get that number of digits.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Scientific notation to string

    So this thread is not about either scientific notation or strings it seems. The question appears to really be about expressions with more precision than Double arithmetic offers.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    472

    Re: Scientific notation to string

    My problem was when I did the arithmetic the Val() and CDbl() functions returned the value in scientific notation. I needed to know how to get it in whole number and not scientific notation.

  14. #14
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] Scientific notation to string

    Well you're still doomed using Double then.

    Data Type Summary

    So anyway, you can use things like:
    Code:
        Dim A, B
        
        A = CDec("79228162514264337593543950335")
        B = A - 1
        MsgBox Format$(B, "#0")
    But to ensure Decimal arithmetic you'll want to leave out any doubts, as in:
    Code:
        Dim A, B
        
        A = CDec("79228162514264337593543950335")
        B = A - CDec(1)
        MsgBox Format$(B, "#0")

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    472

    Re: [RESOLVED] Scientific notation to string

    The Dec part of the CDec() confused me. I thought it's a function for Decimals. Should get it working though.

    What is the proper type of variable I should use if Double is going to give problems. I changed it to Variant as suggested by LaVolpe.

  16. #16
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: [RESOLVED] Scientific notation to string

    Strictly speaking a decimal number is any number represented in base 10, regardless of how many decimal places it has. If you require 20 significant figures it is the only type available in VB6 that can hold that many. Decimal is not a type in its own right, rather a subtype of Variant.

    Your only other option is to spread your large number over several variables which is fairly complicated.
    W o t . S i g

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    472

    Re: [RESOLVED] Scientific notation to string

    Thanks guys. Got it working with Variant and CDec(). English is second language for me so didn't understand it correctly. To me decimals means the digits after the point.

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] Scientific notation to string

    And just to be clear: the Decimal subtype of the Variant type does not contain "base 10" values at all.

    Decimal variables are stored as 96-bit (12-byte) unsigned integers scaled by a variable power of 10. The power of 10 scaling factor specifies the number of digits to the right of the decimal point, and ranges from 0 to 28.

  19. #19
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [RESOLVED] Scientific notation to string

    @dilettante: Did you mean to get the spade out ?

  20. #20
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] Scientific notation to string

    Quote Originally Posted by dilettante View Post
    And just to
    I am impressed that you managed to remember that three years after the fact.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  21. #21
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,424

    Re: [RESOLVED] Scientific notation to string

    Quote Originally Posted by Bezzie View Post
    English is second language for me so didn't understand it correctly. To me decimals means the digits after the point.
    Hi Bezzie,

    A quick English language lesson.xoxoxoxoxoxoxoxoxoxoxoxo

    You're not far out... 'decimals' refers as stated, to the 'base 10'.
    'Decimal Places' is the expression for 'digits after the point'.
    And 'the point' should actually be 'the decimal point'.

    Here endeth the lesson.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  22. #22
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: [RESOLVED] Scientific notation to string

    pop...

    Bezzie hasn't been on this thread for over six years (July 2011)...do you REALLY think OP will read what you wrote?

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    472

    Re: [RESOLVED] Scientific notation to string

    Actually did read it

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