1 / 20

Numbers

Learn about numbers, arithmetic operations, scientific notation, variable declarations, built-in functions, error types, and more in VB.NET. Explore numerical literals, precedence, scientific notation, display methods, variable rules, and error handling.

rrenteria
Download Presentation

Numbers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Numbers

  2. Numbers • Arithmetic Operations • Display numbers in VB.NET • Variables • Built_in Functions • Three types of errors Numbers

  3. Arithmetic Operations • Numbers are called numeric literals • Five arithmetic operations in VB.NET • + addition 3 + 2 • - subtraction 3 - 2 • * multiplication 3 * 2 • / division 3 / 2 • ^ exponentiation 3 ^ 2 Numbers

  4. Precedence of Arithmetic operation Level of precedence: () Inner to outer,left to right ^ Left to right in expression * / Left to right in expression + - Left to right in expression Numbers

  5. Scientific Notation • Scientific notation represents a number by using power of 10 to stand for zeros In VB.Net b • 10 ris written as bEr Numbers

  6. Scientific Notation • r is two digit number preceded by plus sign if r is positive and by a minus sign if r is negative 10 –2010 ^ - 20 1E-20 1.2 • 10 13 1.2 * 10 ^ 13 1.2E+13 • VB.NET’s choice of whether to display a number in a scientific or standard form depends on the magnitude of the number Numbers

  7. Display numbers • One way to show numbers on screen is to display them in a list box. lstNumbers.Items.Add(n) - Display number n as the last item in the list box lstNumbers.Items.Clear() - Erase all the items in the list box Numbers

  8. Demonstration • List a set of numbers in a list box. Numbers

  9. Variables • A variable is a name that is used to refer to an item of data. The value assigned to the variable may change. • Up to 16,838 characters long • Begin with a letter or an underscore • Consist of only letters,digits and underscores • A Variable name is written in lowercase letters except for the first letters of additional words, such as costOfIT201. Numbers

  10. Data Type Numbers

  11. Variable Declaration • Declaration: Dim varName As dataType Variable name Data type Const constantName As dataType = value Variable that can’t change Numbers

  12. Variable Declaration • Dim declares a variable named varName to be of type dataType • Dim causes computer to set aside a location in memory with the same name varName • Dim also put the number zero in that memory location if varName is a numberic variable Numbers

  13. Multiple Declarations • multiple-declaration statements : Dim a, b As Double Dim a As Double, b As Integer Dim c As Double = 2, b As Integer = 5 Numbers

  14. Variable Initialization • Numeric variables are automatically initialized to 0: Dim varName As Double • To specify a nonzero initial value Dim varName As Double = 50 Numbers

  15. Assignment statement • Assignment:(n is a literal) varName = n varName = expression Numbers

  16. Rules for assigning variables • Assign Integer, Long data type to a variable to store whole numbers • Assign Single, Double to a variable to store decimal fraction • Assign String to a variable to store a list of characters • Assign Boolean data type to a variable whose value will be True or false • Assign Date data type to a variable to store date and time information • Assign Object data type to a variable to store reference to an object • Choosing the data type in each group depending on the size o Numbers

  17. Increment variable value • To add 1 to the numeric variable var var = var + 1 • Or as a shortcut var +=1 Numbers

  18. Built-in Functions • Functions associates with one or more values and returns a value(output) • Math.sqrt(n): Returns the square root of n. Math.Sqrt(9) is 3 • Int(n): Returnsgreatest integer less than or equal to n Int(9.7) is 3 Numbers

  19. Built-in Functions • Math.Round(n, r): • number n rounded to r decimal places Math.Round(2.317,1) is 2.3 Math.Round(2.7) is 3 • When n is halfway between two successive whole number, then it rounds to the nearest even number Math.Round(2.5) is 2 Math.Round(3.5) is 4 Numbers

  20. Three Types of Errors • Syntax error – grammatical errors misspellings, omissions,incorrect punctuation • Run-time error occurs when program is running • Logic error program doesn’t perform as it is intended Numbers

More Related