You are on page 1of 2

Format Functions The value of FormatNumber(n, r) is the string containing the number n rounded to r decimal places and displayed

with commas every three digits to the left of the decimal point. The value of FormatCurrency(n, r) is the string consisting of a dollar sign followed by the value of FormatNumber(n, r). FormatCurrency uses the accountants convention of using surrounding parentheses to denote negative amounts. The value of FormatPercent(n, r) is the string consisting of the number n displayed as a percent and rounded to r decimal places. With all three functions, r can be omitted. If so, the number is rounded to 2 decimal places. Strings corresponding to numbers less than 1 in magnitude have a zero to the left of the decimal point. Also, n can be a either a number, a numeric expression, or even a string corresponding to a number. String Functions String.Compare(str1,str2) Compares 2 string values if they have the same content. String.Concat(str1,str2) combine str2 to the last part of str1. String.Copy(str2) Copy the contents of str2 and return it to a string variable. Numeric functions
Math.Abs is the function that returns the absolute value of a number. So Math.Abs(-8) = 8 and Math.Abs(8)= 8. Int is the function that converts a number into an integer by truncating its decimal part and the resulting integer is the largest integer that is smaller than the number. For example, Int(2.4)=2, Int(4.8)=4, Int(4.6)= -5, Int(0.032)=0 and so on. Math.Round is the function that rounds up a number to a certain number of decimal places. The Format is Math.Round (n, m) which means to round a number n to m decimal places. For example, Math.Round (7.2567, 2) =7.26. If m is omitted, it will round the number to an integer value.

Data Type Identification IsDate(n) Returns a Boolean expression of whether the indicated variable is a valid Date type. IsNumeric(n) returns true or false whether a variable n is a numeric or not. IsArray(n) returns a Boolean value of whether a variable n is an array or not. Date Time Functions DateTime.DaysInMontyh(year,month) returns the number of days in a month in a specific year DateTime.IsLeapYear(year) returns a Boolean value T if year has 366 days otherwise false if the total days in the years is 365. DateTime.Compare(date1,date2) compares the two dates if they are the same. Returns: 0 = same contents; -1 = date1 < date2; 1=date1>date2

Program Codes:
Sub Main() 'Format function Dim num As Double = 100.324415 Dim percent As Double = 0.895345 Console.WriteLine(FormatNumber(num, 2)) ' 100.32 Console.WriteLine(FormatCurrency(num, 2)) ' Php100.32 Console.WriteLine(FormatPercent(percent, 2)) '89.53% 'String function Dim str1 As String = "hello" Dim str2 As String = "Hi" Console.WriteLine(String.Compare(str1, "hello")) ' 0 means equal/same Console.WriteLine(String.Concat(str1, str2)) 'helloHi str2 = String.Copy(str1) 'str2 = hello Console.WriteLine(str2) 'hello 'Numeric function Console.WriteLine(Int(2.37)) '2 Console.WriteLine(Math.Abs(-32)) ' 32 Console.WriteLine(Math.Round(32.1234, 2)) '32.12 Console.WriteLine(Math.Round(32.5131)) '33 'Data Type Identification Dim array(23) As Integer Dim date3 As Date = Date.Now Console.WriteLine(IsNumeric(231)) 'True Console.WriteLine(IsDate(date3)) 'True Console.WriteLine(IsArray(array)) ' True 'DateTime Function Dim date1 As Date = Date.Now Dim date2 As Date = date1 Console.WriteLine(DateTime.Compare(date1, date2)) ' 0 means same Console.WriteLine(DateTime.DaysInMonth(2013, 9)) '30 Console.WriteLine(DateTime.IsLeapYear(2013)) ' False Console.WriteLine(DateTime.IsLeapYear(2012)) ' True Console.ReadKey() End Sub

You might also like