1 / 11

The Math Class

The Math Class. The Math Class includes method members that perform common math functions Abs( num ) returns the absolute value Sqrt ( num ) returns a Double value that is the square root of a number. Num must be positive - a negative # will cause a run-time error

temple
Télécharger la présentation

The Math Class

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. The Math Class The Math Class includes method members that perform common math functions Abs(num) returns the absolute value Sqrt(num) returns a Double value that is the square root of a number. Num must be positive - a negative # will cause a run-time error Sign(num) returns the Integer value 1, -1, or 0 when a number is positive, negative or 0 respectively

  2. The Math Class The IsNumeric() function returns True if its argument can be evaluated as a number and False if it cannot. IsNumeric(argument) – argument is a numeric or string expression or a variable Dim strString As String = “123” lblAnswer.text = IsNumeric(strString) ‘True lblAnswer2.text = IsNumeric(2+4) ‘True lblAnswer3.text = IsNumeric(“2+4”) ‘False Do Review 1, page 8-2

  3. The Math Class The Round() Method rounds numeric data to a specified number of decimal places Round(num, places) returns a Double representing a value rounded to a specified number of decimal places Example: Dim sngNumber as Single = 3.4567 lblAnswer.text = math.round(sngNumber, 2) ‘ 3.46 Do Review 2, page 8-2

  4. Formatting Numeric Output The Format() Function converts a number to a formatted string lblAnswer.text = Format(4789, “Currency”) ‘$4,789.00 lblAnswer.text = Format(4789, “Fixed”) ‘4789.00 lblAnswer.text = Format(4789, “Standard”) ‘4,789.00 lblAnswer.text = Format(.06, “Percent”) ‘6.00% lblAnswer.text = Format(4789, “Scientific”) ‘4.79E+3

  5. Business Functions Annuity: A set of payments made on a regular basis for a specified period. When an annuity is a loan, it can be called an installment loan. An annuity can also be an investment, such as a retirement plan. There are 3 functions that return information about an annuity: a payment function Pmt(), a present value function PV(), and a future value function FV().

  6. Business Functions Payment Function Pmt(rate, term, principal) rate is the monthly interest rate (divide by 12) term is the total # of monthly payments (multiply by 12) principal is the amount borrowed (negative #) Calculate monthly payments for a 30 year, $100,000 loan with an interest rate of 6%. sngPayments = pmt(.06/12, 360, -100000) lblAnswer.text = Format(sngPayments, “Currency”)

  7. Business Functions Present Value PV(rate, term, amount) rate is the monthly interest rate (divide by 12) term is the total # of monthly payments (multiply by 12) amount is the dollars paid per payment (negative #) PV would be used to determine the cost of financing a car

  8. Business Functions Present Value Assume you only have $250 to spend on a car each month and you qualify for a 4 year loan with an interest rate of 8%. Present value will tell you the total value you can borrow. Dim sngBorrowAmount as Single sngBorrowAmount = PV(.08/12, 48, -250) ‘10240.48 You could finance a car worth $10,240.48

  9. Business Functions Future Value FV(rate, term, amount) Future value is used if you want to find out how much money you’ll have at the end of an investment term. Assume you invest $500 per month in a retirement plan that earns 8% interest, and you want to know how much you’ll have at the end of 20 years. Dim sngFV as Single = FV(.08/12, 240, -500) ‘294,510.21 To calculate initial investment : 500*20*12= 120,000.00 You would make $174,510.21!! Do Review 5 on page 8-7

  10. The ListBox Control A list box is used to display a list of items A scroll bar appears if the number of list items exceeds the height of the box Use the Items property to type in the items in your listbox Items.Add() method is used to add an item to a list at runtime Items.Remove() method is used to delete a specified item from the list Items.Clear() method deleted the contents of the listbox Do Review 6 on page 8-9

  11. The ComboBox Control A combo box displays a text box for typing an entry and an arrow that can be clicked to choose an item from a list The items in the list box of a combo box have an index value, with 0 being the first index An index of -1 means that none of the items are selected The entry in a combo box changes when the user either types a value or selects a value from the list. Typing a value causes a TextChanged event, and selecting a value raises a SelectedIndexChanged event. Do Review 7 on page 8-12 Modify Review 5 to add combo boxes for the rate and term

More Related