By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,946 Members | 1,610 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,946 IT Pros & Developers. It's quick & easy.

Format a number into Scientific Notation

P: 4
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
Mar 18 '10 #1

✓ answered by ADezii

My Visual Basic is a little rusty, but in VBA this is a relatively simple matter to Format a Number to Scientific Notation:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format(556355367743#, "Scientific")
  2. yields
  3. 5.56E+11
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format(9123.4876, "Scientific")
  2. yields
  3. 9.12E+03
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format(346789987514423#, "Scientific")
  2. yields
  3. 3.47E+14

Share this Question
Share on Google+
8 Replies


ADezii
Expert 5K+
P: 8,705
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.
Mar 18 '10 #2

NeoPa
Expert Mod 15k+
P: 31,769
Try "0.0E+".

There is more about variants of this in the Help system.
Mar 19 '10 #3

P: 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.
Mar 19 '10 #4

ADezii
Expert 5K+
P: 8,705
Just for clarification, you mention VBScript then VB. Which exactly are you referring to, since they are not the same.
Mar 19 '10 #5

P: 4
ADezii

Sorry, I am using VB.
Mar 19 '10 #6

ADezii
Expert 5K+
P: 8,705
My Visual Basic is a little rusty, but in VBA this is a relatively simple matter to Format a Number to Scientific Notation:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format(556355367743#, "Scientific")
  2. yields
  3. 5.56E+11
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format(9123.4876, "Scientific")
  2. yields
  3. 9.12E+03
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format(346789987514423#, "Scientific")
  2. yields
  3. 3.47E+14
Mar 19 '10 #7

P: 4
Thank you Adezii,

That is what I needed.
Mar 19 '10 #8

NeoPa
Expert Mod 15k+
P: 31,769
@caclark
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.
Mar 20 '10 #9

Post your reply

Sign in to post your reply or Sign up for a free account.