Dim c As Currency = 161.64
Dim e As Currency = c * 100
Dim d As Int64 = c * 100
Dim f As Double = c
Dim g As Double = c * 100
Dim h As Double = 161.64
Dim i As Int64 = e
Break
Of course I don’t know what is going on internally, but it looks like:
Dim d As Int64 = c * 100
first c is changed to the double value (161.639…) then * 100, so the result d is 16163 and i is correct with 16164
I agree Christian, I expect this:
See ‘c’ as currency, check that there is an operation, treat the operation as currency, then the final result (as currency) assign it to ‘d’ that is Int64.
Something like:
Dim c As Currency = 161.64
Dim e As Currency = c * 100
Dim d As Int64 = c * 100 // currency, same as 'e'
I guess the currency calculation is not wrong, but the way the calculation is done when assigned to a non currency variable, right?
I think this is the first time I see ‘ctype’ (still lot to learn). Reading about ctype I see this:
Then what Greg posted:
Dim e As Int64 = ctype(c * 100, currency)
Then what an user could expect with c is currency but we are using = to Int64:
a) c considered as Int64 then * 100, result should be 16100, like:
Dim c As Currency = 161.64
Dim d As Int64 = c
d = d * 100
or
b) c considered as currency * 100, result converted to Int64, like:
Dim c As Currency = 161.64
Dim e As Currency = c * 100
Dim d As Int64 = e
but in reality we get d = 16163
Dim c As Currency = 161.64
Dim d As Int64 = c * 100
If we use a decimal plugin with this code:
Dim c As Decimal = 161.64
Dim d As Int64 = c * 100
we get d = 16164
as we original expected. My guess is, because the decimal plugin is not a Xojo data type, then Xojo does not convert it to double to do the * 100 calculation and we get the expected result.