Format a number into Scientific Notation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • caclark
    New Member
    • Mar 2010
    • 4

    Format a number into Scientific Notation

    I am begining to work on a VBscript to use inside a MS Access Query, so I started to do a little looking around the web to see if there was already a built-in VB function or at lease an example of one to convert a large number (6 sign. digits & larger) into SN (Scientific Notation) format for manipulation later within my script.

    Example:
    Input format: 550000000
    SN format: 5.5E+8

    I can find all kinds of examples for about every other type of programming language imaginable, but not VBscript.

    Surly I am not the first person on the planet that has need of something like this!!

    Can anyone please help steer me in the right direction?

    Chris
    Last edited by caclark; Mar 18 '10, 06:14 PM. Reason: Added an example of formatting
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Not positive, but I think that you may be out of luck as far as doing this in VB Script unles you create your own Custom sn Formatting.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      Try "0.0E+".

      There is more about variants of this in the Help system.

      Comment

      • caclark
        New Member
        • Mar 2010
        • 4

        #4
        NeoPa

        Thanks for your help, but how I am not all that familiar with VB. All other languages have used including JS have some sort of "format" call to do just what you described above, but I don't see anything that even closely resembles this in VB.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Just for clarification, you mention VBScript then VB. Which exactly are you referring to, since they are not the same.

          Comment

          • caclark
            New Member
            • Mar 2010
            • 4

            #6
            ADezii

            Sorry, I am using VB.

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              My Visual Basic is a little rusty, but in VBA this is a relatively simple matter to Format a Number to Scientific Notation:
              Code:
              Debug.Print Format(556355367743#, "Scientific")
              yields
              5.56E+11
              Code:
              Debug.Print Format(9123.4876, "Scientific")
              yields
              9.12E+03
              Code:
              Debug.Print Format(346789987514423#, "Scientific")
              yields
              3.47E+14

              Comment

              • caclark
                New Member
                • Mar 2010
                • 4

                #8
                Thank you Adezii,

                That is what I needed.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32656

                  #9
                  Originally posted by caclark
                  NeoPa

                  Thanks for your help, but how I am not all that familiar with VB. All other languages have used including JS have some sort of "format" call to do just what you described above, but I don't see anything that even closely resembles this in VB.
                  I'm sorry. My answer assumed you were aware of the Format() function.

                  You have already now heard of that and how to use it in it's basic form. The parameter "Scientific " is another perfectly good alternative to the parameter I suggested (0.0E+), but you will find if you look in the Help about it, that there are variations you can specify if you're interested that give you a little more control of how the value is displayed. In most cases I expect the default ("Scientific ") is what you want.

                  Comment

                  Working...