just found this one :
used the JSON xojo example, and modified it to add a currency to the json
Var Person As New JSONItem
Dim c As Currency = 27.32
// This object is manipulated like a dictionary
Person.Value("Name") = "John Doe"
Person.Value("Age") = 32
Person.Value("Married") = True
Person.Value("curr") = c
Person.Value("Spouse") = "Jane Doe"
Var s As String = Person.ToString
There was an exhaustive thread on this forum some months ago concerning this very issue. Many solutions were proposed, which would be better than using a Double.
You may also assume ints with 4 fixed decimals in some of your values as
“money1” : 1234567,
“money2” : 1234500
means currency 123.4567 and 123.45
Public Function BoxedAsInteger(extends value As Currency) As Int64
// Read a Currency as an Int64 with the lower 4 digits being the decimal part
Var mb As New MemoryBlock(8)
mb.CurrencyValue(0) = value
Return mb.Int64Value(0)
End Function
Public Function UnboxedAsCurrency(extends value As Int64) As Currency
// Read an Int64 as a 4 decimal fixed point money value
Var mb As New MemoryBlock(8)
mb.Int64Value(0) = value
Return mb.CurrencyValue(0)
End Function
why not convert the value to cents as integer so that there is never an issue?
Having floats/doubles, strings etc would only make things harder.
Most banking apis use cents so that it’s easy to convert and present.
Have in mind that those 15 digits are 99,999,999,999.9999 (99… billions) and it is too small for accounting in Brazil, as gov numbers reaches Trillions. For small businesses it is ok even here.
But doubles are not enough anymore for gov numbers.