Skip to main content

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
Status: Completed1 comment

Log in to comment and vote

Comments1

  • Rambod Rahmani

    •

    Jun 1, 2025

    I am starting this goal as it is happening in production