Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1463

Currency Problems

$
0
0
I use this to get a value as signed long,
Code:

Public Function Signed(A) As Long
    Dim p
    p = Fix(CDec(A))
    Signed = MemLong(VarPtr(p) + 8)
End Function

Its ok, but this has a correction. The previous formula was:
p = CDec(Int(A))

What's wrong?
If we have a Currency type A say 100 the Signed return 1000000...Why?
Because p as VBDecimal not store 100 as binary, but the actual binary form of Currency, which is multiplied by 1000 and just pass a "decimal shift" of 4 digits, a division of 1000. So the right formula is the Fix(CDec(A)) which first place the Currency type as is in a Decimal type, and then the Fix() statement just remove the "decimal shif" applying the division.

The MemLong() function is from https://github.com/cristianbuse/VBA-MemoryTools

The signed() function works with type 20 (Long Long) too. So it is the low 4 bytes of a Long Long.

Viewing all articles
Browse latest Browse all 1463

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>