Closed LeonB closed 5 years ago
Hey Leon,
The API won't handle 6dp either so the best solution would be to round on your side before you send it.
There is a guide to rounding in Xero available here if you want to see how we handle rounding.
Hi Regan, the decimal positions are not the problem. It's the numbers in front on the dot. The library/Go converts 123456789.0
to 1.23456789e+08
Hi @TheRegan,
As Leon says it has to do with the encoding of numbers bigger than a million, not with decimals. The max amount of decimals we send over is 4. The problem occurs with the encoding of XML that isn't correct in the library of Go. Here floats that are bigger than a million are converted to scientific notation as described above. The encoding of JSON in the Go Library was fixed in the past, so there the floats that are bigger than a million aren't converted to scientific notation. That why Leon asked if we can send over JSON instead of XML.
There's an issue in the library/Go with encoding floats. The default in Go is to marshal floats with more then 6 digits to the scientific notation. Here's an example: https://play.golang.org/p/wgLouDNloYq
We're doing some integration work where the used currency is the Indonesian Rupiah. So the 6 digits are quickly reached when sending manual Journals. The scientific notation is (understandably) not accepted by the Xero api.
I think there're two options to fix this: don't use xml.Marshal for the request data. I don't really understand why this is used in the first place? Or make a custom type / alias for the float64 and customize how the float is marshalled to xml.