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

Problem with cents in v6.5.1 #123

Closed
quintavallechristian opened this issue May 31, 2022 · 12 comments
Closed

Problem with cents in v6.5.1 #123

quintavallechristian opened this issue May 31, 2022 · 12 comments

Comments

@quintavallechristian
Copy link

Updating to the last version (coming from 3.8) I noticed all the amounts in my application multiplied by 100. It seems like the format() function does not divide by 100 anymore, so if I pass a value of 100 it will print 100 € (or whatever currency I set).

Rolling back to version 6.4.0 the problem disappears

@ReadingPride
Copy link

ReadingPride commented Jun 6, 2022

We had the same problem, although this was just a general composer update for us, not expecting any code breaking or significant changes from it so this caught us out by surprise until it was reported.

@marvinschroeder
Copy link

Same problem here.

@hrnicek
Copy link

hrnicek commented Jun 9, 2022

Same problem

@ricardogobbosouza
Copy link
Member

Hi @quintavallechristian
Could you share an example of the error?

@marvinschroeder
Copy link

marvinschroeder commented Jun 14, 2022

@ricardogobbosouza

This problem only occurs with float's.

In v6.4.0 this was the behavior:

money(250, 'EUR') // 2,50 €
money(2.50 * 100, 'EUR') // 2,50 €

In v6.5.1:

money(250, 'EUR') // 2,50 €
money(2.50 * 100, 'EUR') // 250,00 €

@ricardogobbosouza
Copy link
Member

ricardogobbosouza commented Jun 14, 2022

Actually, this is expected now

Because 250 is not equal to (2.50 * 100) = 250.0

We have different treatments for integers and floating
https://github.com/cknow/laravel-money/blob/main/src/MoneyParserTrait.php#L32-L74

And with that the option forceDecimals was added
https://github.com/cknow/laravel-money/blob/main/src/Money.php#L73-L76

Maybe this should have been a breaking change and released v7 🤔

@marvinschroeder
Copy link

If that is expected now, it is indeed a breaking change and better suited for a new major version.

@ricardogobbosouza
Copy link
Member

I treated this as a fix

In v6.4.0

@money(2.50 * 101) = $2.52 // wrong

In v6.5.1:

@money(2.50 * 101) = $252.50 // right

@ricardogobbosouza
Copy link
Member

I will remove the latest versions and release v7

@ricardogobbosouza
Copy link
Member

Sorry for the trouble with the floating values
Released v7.0.0

@jtomek
Copy link

jtomek commented Jun 18, 2022

This was indeed a breaking change. Our app reports significant numeric changes to our clients and suddenly we generated quite a number of notifications because all figures suddenly went up by x100. :) We need to add more testing.

@giacomomasseron
Copy link

I treated this as a fix

In v6.4.0

@money(2.50 * 101) = $2.52 // wrong

why this should be wrong?

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

No branches or pull requests

7 participants