Summary
In modules/price/src/Calculator.php, the check for a decimal point uses strpos($number, '.') != FALSE, which fails when the decimal point is at position 0 (e.g. '.5'). In that case strpos returns 0, and 0 != FALSE is false, so the decimal point is not detected.
Steps to reproduce
- Call
Calculator::trim('.5')or any string where the decimal point is at index 0. - Observe that trailing zeros are not stripped because the decimal point is not recognized.
Proposed solution
Replace the loose comparison with either:
strpos($number, '.') !== false, orstr_contains($number, '.')(PHP 8+).
Impact
This is a common PHP pitfall: when checking for substring presence, use strict comparison with false or str_contains() in PHP 8+.
Issue fork commerce-3579797
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
tbkot commentedComment #5
super_romeo commentedLooks good.
Comment #8
jsacksick commentedLooks good! Merged thanks!