【问题标题】:Equivalent of Currency in VB.Net?VB.Net中的货币等价物?
【发布时间】:2020-05-07 09:13:31
【问题描述】:

我正在将应用程序从 VB6 迁移到 VB.Net,它使用货币类/结构。 我的问题是:以下代码中 VB6 Currency 的“等价物”是什么?

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' 在 VB.Net 中会出现这样的错误。是否有任何缺少的库,这是必须的?

【问题讨论】:

  • 我知道货币被存储为一个 8 字节整数,假设有四个小数位。在使用存储 VB 货币数字并在 Crystal Reports 中报告它们的旧 Btrieve 数据库时,我必须始终将这些值除以 10,000 以获得真实的货币值。

标签: vb.net vb6 migration vb6-migration


【解决方案1】:

表示货币的数据应在 VB.NET 中存储为Decimal 值。它不像Double 那样容易出现舍入错误。

【讨论】:

    猜你喜欢
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-27
    • 2020-08-04
    • 2023-03-09
    • 1970-01-01
    • 2012-05-19
    相关资源
    最近更新 更多