Overview

Scientific notation (also called exponential 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.

You would 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

 

Examples in Small Basic

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!

Limitation

Internally the Exponential is still converted to Decimal type for calculations so you are limited to about 7E28, which is the maximum Decimal 2^96-1



So this works: TextWindow.WriteLine(1*"7E28")



And this fails:  TextWindow.WriteLine(2*"7E28")

Credits

The article was originally written by Ed Price and Majed Marji. You can find earlier drafts on Ed's blog and on the Small Basic official blog. LitDev provided additional limitation information. 

See Also

 

Other Resources