mediaopt / braintree-commercetools-connector

MIT License
1 stars 3 forks source link

Decimal issue in map.util.ts > mapBraintreeMoneyToCommercetoolsMoney #56

Closed romit-c-tadigital closed 10 months ago

romit-c-tadigital commented 10 months ago

mapBraintreeMoneyToCommercetoolsMoney accepts a string amount and number of fraction digits. It gives the expected output for most of the numbers, but doesn't work correctly for some other numbers. Example input - amount = 65.32 fractionDigits = 2 Expected output = 6532 Actual output = 6531.999999999999

I don't have any other number as of now for which I am not getting expected output but it may happen that when expected output is XXXX, the function returns XXXX.00000000001. Hence the new logic should support both the cases i.e. rounding up & down as applicable in that case.

Also, if possible, it will be good to have a unit test just testing this function and mapCommercetoolsMoneyToBraintreeMoney function with an array of combinations of amount and fractionDigits.