Small Basic – Scientific Notation


Scientific notation is a way to write numbers that are too large or too small. For example, a microbiologist might need to measure cell growth up to 0.000000005 of a micron.

Use scientific notation to write the number 56,372.85 as 5.637285´104 (where 104 is 10000; the decimal goes to the right four spots). In most programming languages, you can use E-notation to represent decimal numbers.

In E-notation, the number 56,372.85 is written as 5.637285E4. The part of the number after the E is the power of 10. The E4 in this example means “times ten to the fourth power.” The Table shows you the E representation of some numbers.

  

Table: Examples of E-notation

Number

E-Notation

3563.21

3.56321E+03

0.000356

3.56E-04

56,000,000

5.6 E+07

 

Small Basic doesn’t treat E-notations like other numbers; you can’t assign an E-notation to a variable. For example, this statement gives you a syntax error:

x = 1.2E+02 ' This gives you a syntax error. You're welcome.

 

But if you put the E-notation in double quotes, then Small Basic recognizes it as a number! This is a parser feature to make it clear (to you and to Small Basic) that you meant it to be an E-notation. Try out this code snippet to get a hang of it:

x = "1.2E+02"   '= 120

y = "5.0E-02"   '= 0.05

z = "1.0E+03"   '= 1000

TextWindow.WriteLine(x + x)   'Answer = 240

TextWindow.WriteLine(x * y)   'Answer = 6.000

TextWindow.WriteLine(x / y)   'Answer = 2400 

TextWindow.WriteLine(z - x)   'Answer = 880

 

Now you can use E-notation when you need to!

 

Head to http://blogs.msdn.com/SmallBasic to download it and learn all about it!

 

Small and Basically yours,

   - Ninja Ed & Majed Marji

Comments (5)

  1. Thank you for your information.  I didn't know about Exponential Notation for Small Basic!

  2. Nonki, well there you go! I did my good deed for the year! =^)

  3. Computers Today (part 1 of 6)

    blogs.msdn.com/…/computers-today.aspx

    …..

    CS SPOTLIGHT: Girls in computer programming… why it matters!!!

    blogs.msdn.com/…/cs-spotlight-girls-in-computer-programming-why-it-matters.aspx

    Computational Thinking – Videos & Papers by Jeannette Wing

    blogs.msdn.com/…/computational-thinking-videos-amp-papers-by-jeannette-wing.aspx

Skip to main content