VB Currency Example

← All NMath Code Examples

 

Imports System
Imports System.IO
Imports System.Threading
Imports System.Globalization

Imports CenterSpace.NMath.Core

Namespace CenterSpace.NMath.Core.Examples.VisualBasic

  ' A .NET example in Visual Basic showing how to read and write vectors of currencies.
  Module CurrencyExample

    Sub Main()

      Console.WriteLine()

      ' American
      Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")

      ' Create a vector of US currency values
      Dim v As New DoubleVector("$4.30 $0.08 ($5.87)", _
         NumberStyles.Number Or NumberStyles.AllowCurrencySymbol Or NumberStyles.AllowParentheses)

      ' Dollars
      Console.Out.WriteLine(v.ToString("C"))

      ' Convert it to Pounds
      v = v * 0.6823 ' exchange rate

      ' Round to two decimal places
      v = NMathFunctions.Round(v, 2)

      ' I'm British
      Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
      Console.Out.WriteLine(v.ToString("C"))

      Console.WriteLine()
      Console.WriteLine("Press Enter Key")
      Console.Read()

    End Sub

  End Module

End Namespace

← All NMath Code Examples
Top