Equivalent of Currency in VB.Net?

Viewed 326

I am migrating an application from VB6 to VB.Net, Which is using the Currency Class/Structure. My question is: Which is the "equivalent" of VB6 Currency in following Code?

Public Function getTimeElapsed() As Double

    Dim cuStart As Currency
    Dim cuStop As Currency
    Dim cuFreq As Currency
    Dim v As Double
    Dim ReturnValue As Double

    QueryPerformanceFrequency(liFrequency)

    cuStart = LargeIntToCurrency(liStart)
    cuStop = LargeIntToCurrency(liStop)
    cuFreq = LargeIntToCurrency(liFrequency)
    ' elapsed time
    v = CDbl(cuStop - cuStart) / CDbl(cuFreq)
    Select Case ResultUnit
        Case CounterUnit.Second
            ReturnValue = v
        Case CounterUnit.Millisecond
            ReturnValue = v * 1000.0#
        Case CounterUnit.microsecond
            ReturnValue = v * 1000000.0#
        Case CounterUnit.nanosecond
            ReturnValue = v * 1000000000.0#
    End Select
    Return ReturnValue
End Function
Private Function LargeIntToCurrency(liInput As LARGE_INTEGER) As Currency
    CopyMemory(LargeIntToCurrency, liInput, Strings.Len(liInput))
    LargeIntToCurrency = LargeIntToCurrency * 10000
End Function

'Currency' gives error like this in VB.Net. Is there any missing library, which must for it?

enter image description here

1 Answers

Data representing currency should be stored as Decimal values in VB.NET. It is not susceptible to rounding errors the way Double is.

Related