Fix Floating-Point Precision Errors in Calculations

Description:

We're encountering floating-point precision issues when performing arithmetic with decimal numbers. For example, multiplying 16.67 * 100 results in 1667.0000000000002 instead of the expected 1667. This is due to how JavaScript (and most programming languages) handle floating-point numbers using the IEEE 754 standard, which cannot represent all decimal fractions precisely in binary.

Impact:

This causes inconsistencies in calculations, especially when:

  • Comparing numbers for equality

  • Using results in currency/financial operations

  • Displaying values to end users

Examples:

16.67 * 100 // 1667.0000000000002 โŒ 
1.005 * 100 // 100.49999999999999 โŒ 

Suggested Fix:

Apply rounding consistently after calculations that involve floating-point numbers. For example:

Math.round(value * 100) parseFloat((value * 100).toFixed(2)) 


this happens for example while cacluating the recurring coupon amount that




fix this and other occurances

Domain
Payment
Action
fix
Department
Backend

Please authenticate to join the conversation.

Upvoters
Status

Completed

Board
๐Ÿ› ๏ธ

Bug & Fixes

Date

10 months ago

Author

Abdulmelik Ambaw

Subscribe to post

Get notified by email when there are changes.