VB.Net Tutorial/Data Type/Number Function

Материал из VB Эксперт
Версия от 15:54, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

CInt

<source lang="vbnet">public class Test

   Public Const MAX_VALUES As Integer = CInt(123.45)
  public Shared Sub Main
       
  End Sub

End class</source>

CInt: convert Hexadecimal in string to int

<source lang="vbnet">Option Strict On Public Module modMain

  Public Sub Main()
     Dim convertedHex As Integer = CInt("&H75FF")
     Console.WriteLine(convertedHex)     
  End Sub

End Module</source>

30207

Fix

<source lang="vbnet">Option Strict On Public Module FixTest

  Public Sub Main()
     Dim arr() As Decimal = {12.6d, 12.1d, -12.1d, -12.6d}
     For Each num As Decimal In arr
        Console.WriteLine("Fix({0}): {1}", num, Fix(num))
        Console.WriteLine("Int({0}): {1}", num, Int(num))
        Console.WriteLine()
     Next
  End Sub

End Module</source>

Fix(12.6): 12
Int(12.6): 12
Fix(12.1): 12
Int(12.1): 12
Fix(-12.1): -12
Int(-12.1): -13
Fix(-12.6): -12
Int(-12.6): -13

Math.Round with IRR

<source lang="vbnet">Option Strict On Public Module modMain

  Public Sub Main()
     Dim cashFlow() As Double = {-102450.55, -30967.12, 134.85, 82930.91, _
                                 121766.18, 90345.58, 125093.16}
     Dim guess As Double = .15
     Console.WriteLine("{0}", Math.Round(IRR(cashFlow, guess)*100,1))
  End Sub

End Module</source>

31.1%