recurly-client-go icon indicating copy to clipboard operation
recurly-client-go copied to clipboard

Library uses float which causes rounding errors

Open Talljoe opened this issue 5 years ago • 3 comments

Describe the bug

The Go library uses float for monetary values. Float is widely discouraged as it does not contain the necessary precision to handle currency values.

To Reproduce

Fetch a credit invoice of $-79.99. Multiply by 100.0 and convert to an `int:

// invoice.Subtotal = -79.99
x = int(invoice.Subtotal * 100.0)
assert.equal(-7999, x)
Error: Not equal:
       expected: -7999
       actual  : -7998

Expected behavior

Library should use a Decimal or other fixed-point

Your Environment

  • Which version of this library are you using? v3.8.0 f4d23f429fa01778f037d3b88c04c380f8fd745d
  • Which version of golang are you using? 1.14.9

Talljoe avatar Oct 27 '20 20:10 Talljoe

Thank you for reporting this @Talljoe. We are aware of this limitation and are investigating solutions that we can employ in our upcoming 4.x client release. Updating the 3.x client would introduce a breaking change to existing implementations, unfortunately. We will leave this issue open and will provide updates when they become available.

douglasmiller avatar Oct 28 '20 17:10 douglasmiller

Have there been any updates on this @douglasmiller?

speza avatar May 10 '21 08:05 speza

This was 4 years ago and it's still not fixed in the product? I just submitted a support ticket. This issue results in incorrect billing calculations.

wellsync-matt-may avatar Jul 30 '24 13:07 wellsync-matt-may