XeroAPI / xerogolang

Golang SDK for the Xero API
MIT License
24 stars 29 forks source link

Rounding issue #20

Closed LeonB closed 5 years ago

LeonB commented 5 years ago

Because of the use of float32's there sometimes appear rounding issues:

package main

import (
    "encoding/json"
    "log"

    "github.com/XeroAPI/xerogolang/accounting"
)

func main() {
    line := accounting.ManualJournalLine{
        LineAmount: 259467.21,
    }

    b, _ := json.MarshalIndent(line, "", "  ")
    log.Println(string(b))
}
$ go run test.go 
2018/12/11 11:36:22 {
  "AccountCode": "",
  "LineAmount": 259467.2
}

Changing the float32's to float64 in the library fixes this issue. Is that a pull request that would be accepted?

TheRegan commented 5 years ago

Hey Leon,

Changing this would be a breaking change. Normally I would be hesitant to do this but we've just added modules which will allow people wanting to keep float32's to use an older version if they want.

This was an oversight on my part by the way, it 100% should have been float64 from the beginning but I didn't pick up on it. So many apologies!

If you flick through a PR with the changes I'll happily accept it.

LeonB commented 5 years ago

No worries. I've submitted the PR. That's for the quick response. Some kind of Decimal type would be even better.