Zalak Parikh
Zalak Parikh

Reputation: 49

Equivalent of Currency in VB.Net?

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

Upvotes: 3

Views: 785

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54417

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

Upvotes: 7

Related Questions