Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BcMathNumber::performOperation] Specified scale 0 conflict #4

Closed
fyrye opened this issue Jan 25, 2018 · 1 comment · Fixed by #5
Closed

[BcMathNumber::performOperation] Specified scale 0 conflict #4

fyrye opened this issue Jan 25, 2018 · 1 comment · Fixed by #5

Comments

@fyrye
Copy link
Contributor

fyrye commented Jan 25, 2018

The determination of scale in BcMathNumber::performOperation returns unexpected results.

$scale = (int) ($scale ?: self::$defaultScale);

Will return as self::defaultScale when a scale of 0 is specified.
e.g.

echo BcMathNumber::create('123.45')
   ->add('1', 0)
   ->getValue(); 
   //returns 124.45000000 - expected 124

vs https://3v4l.org/ib3ZC

echo bcadd('123.45', '1', 0); //124

The line should be changed to read:

$scale = (int) (null === $scale ? self::$defaultScale : $scale);
@dbojdo dbojdo closed this as completed in #5 Jan 25, 2018
dbojdo pushed a commit that referenced this issue Jan 25, 2018
Issue: Specified scale of 0 resulting in use of the declared default scale.
Resolution: use default scale only when specified scale is null.
This closes #4
@dbojdo
Copy link
Owner

dbojdo commented Jan 25, 2018

@fyrye Thanks for pointing it out. I've put some tests in place to cover this case and I've fixed some more issues I've found during this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants