BCMath is used to perform arithmetic calculations within Fraction class methods. This enables better precision than PHP float value arithmetic.

Currently, many of the BCMath function calls in fraction.class.inc do not set a scale parameter, which means the scale will default to whatever the global default scale is. If no default global scale is set, it defaults to zero. Fraction needs to use a scale of zero to ensure that the numerator/denominator are always whole numbers. If the scale is set globally using bcscale, then this assumption is broken. So we should explicitly set the scale to zero wherever it is used.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

m.stenta created an issue. See original summary.

m.stenta’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Active » Patch (to be ported)
FileSize
2.88 KB

Committed.

Attached is the patch. Needs to be ported to 8.x-1.x.

m.stenta’s picture

  • m.stenta committed add0600 on 7.x-1.x
    Issue #2921422: Use scale of 0 in all numerator/denominator BCMath...
pcambra’s picture

Status: Patch (to be ported) » Needs review
FileSize
2.87 KB

  • m.stenta committed 0ed2404 on 8.x-1.x authored by pcambra
    Issue #2921422 by m.stenta, pcambra: Use scale of 0 in all numerator/...
m.stenta’s picture

Status: Needs review » Fixed

Merged - thanks @pcambra!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.