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

DomainPayment
Actionfix
DepartmentBackend

Please authenticate to join the conversation.

Upvoters
Status

Completed

Board
🛠️

Bug & Fixes

Date

Over 1 year ago

Author

Abdulmelik Ambaw

Subscribe to request

Get notified by email when there are changes.