Page 45 -
P. 45
2-5 常見內建函式 第二章 運算式
(一)數值函式: 輸出結果
1. Int(a):傳回小於或等於 a 的最大整數。
2. Fix(a):將 a 的小數部分無條件捨去。
3. Sqrt(a):求 a 的平方根。
4. Math.Abs(a):求 a 的絕對值。
5.Math.Round(a,n):求 a 的四捨五入的值,到小數點第 n 位數。
6. Math.Max(a,b):傳回二個數字大的那一個。
7. Math.Min(a,b):傳回二個數字小的那一個。
範列如下:
Dim a As Single = 12.345
Dim b As Single = -12.345
Dim c As Integer = 12, d As Integer = 15
Console.WriteLine(Int(a))
Console.WriteLine(Int(b))
Console.WriteLine(Fix(a))
Console.WriteLine(Fix(b))
Console.WriteLine(Math.Abs(b))
Console.WriteLine(Math.Round(a, 2))
Console.WriteLine(Math.Max(c, d))
Console.WriteLine(Math.Min(c, d))
(二)字串函式:
1. Chr (ASCII 值):傳回該 ASCII 值所對應的字元。
2. Asc("字元"):傳回該字元的 ASCII 值。
3. Len("字串"):計算該字串的長度。
4. Left("字串", n):取該字串左邊的 n 個字元。
5. Right("字串", n):取該字串右邊的 n 個字元。
6. Mid("字串", m, n):從字串的第 m 個字元開始,取 n 個字元。
41