Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When.

Similar presentations


Presentation on theme: "Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When."— Presentation transcript:

1 Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When we measure things, we need Rea Numbers or fractions.

2 Numbers2 Counting Things BYTE  Small range of values, 0 to 255 INTEGER  -32,768 to +32,767 LONG (integer)  -2,147,483,648 to +2,147,483,647 (no fractions, no rounding, fast and efficient means of working with whole numbers)

3 Numbers3 Measuring Things SINGLE (precision floating point)  +1.401298E-45 to +3.402823E38 DOUBLE (precision floating point)  +4.94065645841247E-327 to +1.79769313486232E308 (same range for negative numbers, data is rounded to either 7 or 14 digits of accuracy)

4 Numbers4 Highest Precision CURRENCY (scaled integer)  +/-922,337,203,685,477.5807 DECIMAL  +/-79,228,162,514,262,337,593,543,950,335 or +/-7.9228162514262337593543950335 (no rounding, slow but sure) BOOLEAN  False to True

5 Numbers5 Storage Space & Prefixes BYTE 1 byte byt INTEGER 2 bytesint LONG 4 byteslng SINGLE 4 bytessng DOUBLE 8 bytesdbl BOOLEAN 2 bytesbln CURRENCY 8 bytescur DECIMAL14 bytesdec

6 Numbers6 Good Practice You should give a numerical variables in Visual Basic a name that begins with an appropriate 3 character string. The 3 character string used is a good clue to the limits and the accuracy of the data type chosen. (The name is seen only by programmers)

7 Numbers7 Establishing Values Dim intValue as integer intValue = 12 intValue = ”12” intValue = 12.5 intValue = 11.51 all result in the integer variable intValue being set to the number 12

8 Numbers8 Operators 1.^  Exponentiation 2.-  Unary Negation 3.* /  Multiplication and Division 4.\  Integer Division 5. MOD  Remainder 6.+ -  Addition and Subtraction (otherwise left to right)

9 Numbers9 Precedence Examples sng A = ( 3 + 4 ) / ( 2 - 3 ) results: sng A = -7.00 sng B = ( 3 + 4 ) / 2 - 3 results: sng B = 0.50 sng C = 3 * 4 / 2 * 3 results: sng C = 18.00 sng D = ( 3 * 4 ) / ( 2 * 3 ) results: sng D = 2.00

10 Numbers10 Real & Integer Arithmetic sng A = 5 / 2 results: sngA = 2.50 sng B = 5 \ 2 results: sngB = 2.00 int C = 5 MOD 2 results: int C = 1 int D = 5 / 2 results: intD = 2

11 Numbers11 Numerical Functions In addition to the operators, there are a great many functions that may be used to process numbers. A few of them follow this slide.

12 Numbers12 Numerical Functions intA = ABS( -5 ) results: int A = 5 (zero or positive) intB = SGN( -3 ) results: int B = -1 (either 1, 0 or -1) intC = INT( 6 * RND + 1 ) results: intC will be 1, 2, 3, 4, 5 or 6

13 Numbers13 Format Function (1)

14 Numbers14 Format Function (2) sngFoo = val(txtFoobar.Text) Label1.Caption = _ (note the underscores) Format(sngFoo, ”$#,##0.00”) Label2.Caption = _ Format(sngFoo, ”h:mmAMPM”) Label3.Caption = _ Format(sngFoo, "0.000e+00")

15 Numbers15 Format Function (3) For more information on the Format Function see page 82 and page 264 in the textbook.

16 Numbers16 To Learn More... Using VB Help, remember to get into the “visual basic documentation” active subset. Enter the keyword “format” and click on “format function”.


Download ppt "Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When."

Similar presentations


Ads by Google