Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Decimal Types. What are the data types that you can use? Decimal Number: Single -Is used for decimal values that will not exceed six or seven digits.

Similar presentations


Presentation on theme: "Using Decimal Types. What are the data types that you can use? Decimal Number: Single -Is used for decimal values that will not exceed six or seven digits."— Presentation transcript:

1 Using Decimal Types

2 What are the data types that you can use? Decimal Number: Single -Is used for decimal values that will not exceed six or seven digits. Double - Is used for decimal values with more than six or seven digits. Currency - Is used when working with dollars and cents.

3 Using the Format Function! Allows you to apply custom formatting to a number before displaying the value. Use it for: –Decimal values –Phone numbers –Currency $$$$$ –Social security numbers –ID numbers –Dates –Time

4 How? You specify the format you want using special symbols. For example: Display 1234.56 to appear as $1,234.56 strAmount = Format(1234.56, “$#,###.00”)

5 Formatting Symbols SymbolDescription 0 The 0 symbol causes a digit to appear in the space. If the data has no value for that digit, a zero appears. # Is similar to the 0 symbol. The difference is that nothing appears in the space if the number being formatted does not require that digit to be used.. The period is used to specify where you want the decimal point to appear in the format.

6 SymbolDescription, By placing commas in the format it will appear in the format. % The percent sign causes a number to be multiplied by 100 and a percent sign to be placed at the end of the number.

7 Examples! CodeResult Format(12345.67, “000000.000”012345.670 Format(12345.67, “######.000”) 12345.670 Format(12345.67, “######.###”) 12345.67 Format(12345.67, “###,###.##”) 12,345,67 Fomat(12345.67, “$###,###.##”) $12,345.67 Format(0.89, “##%”) 89%

8 Let’s look at a program. Open Visual Basic Open the Dog Years program from the c:\drive. Double click the Calculate age in months. Enter the following code: ‘Display Number of Months Old lblOutputMonths.Caption = “You are” & intMonths & “months old.” lblOUtputMonths.Visible = True

9 Double click the Calculate age in months. Enter the following code: ‘Display Instructions lblInstructions.Visible = True Double click the Dog button. Enter the following code: Dim strYears As String Dim sngYears As Single ‘Calculate Dog Years sngYears = (7 * intMonths) / 12 ‘Hide Instructions lblInstructions.Visible = False

10 ‘Display Results strYears = Format(sngYears, “###.0”) lblOutputAnimalYears.Caption = “In dog years, you are “ & strYears & “years old.” lblOutputAnimalYears.Visible = True

11 Close the code window and run the program. Enter 15 in the Age in years Enter 4 in the Months since last birthday Click the Calculate age in months and dog buttons. What happens?


Download ppt "Using Decimal Types. What are the data types that you can use? Decimal Number: Single -Is used for decimal values that will not exceed six or seven digits."

Similar presentations


Ads by Google