VB.Net Tutorial/Data Type/Number Function

Материал из VB Эксперт
Перейти к: навигация, поиск

CInt

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

CInt: convert Hexadecimal in string to int

Option Strict On
Public Module modMain
   Public Sub Main()
      Dim convertedHex As Integer = CInt("&H75FF")
      Console.WriteLine(convertedHex)     
   End Sub
End Module
30207

Fix

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
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

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
31.1%