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
[MoneyBundle] Configurable round mode #10204
Comments
Well, I don't see a use-case for that. Is there a currency where one unit is split into thousands? |
I have 2 in mind where I've been forced to change the rounding mode.
|
Okay, this makes sense. I mean feel free to make a pull request. And see what the Sylius people think. |
Coming back here with an update. Not entirely linked to this functionnality, but this might increase the following bug : If we store a currency in ten thousands of a unit and this currency has crazy amounts, like Japanese Yen for example. If you sell an item at ¥499 777,27 (approx 4000 euros) or a cart total at this price. You'll reach the SQL limit. I'm sure that at the moment it's not really a problem with the hundredth rounding mode and using currencies like euro, dollar or any currency that has the same value. Any ideas ? |
Valid point. For this we should use a different datatype but I'd suggest to use the BIGINT then. |
Doctrine does convert BIGINT to string in PHP |
Never heard of this but looks like it. Then it doesn't matter. |
As a matter of fact, it matters. |
Classic programming problem! So it seems that MySQL uses 32 bit signed integers (at least the max value of For some countries however the limit might be reached quite fast, just consider Vietnam for example: 50 euro's is worth more than 1,000,000 dong. In this case though the least significant bits are truly quite insignificant and people will ignore pretty much everything under a thousand, allowing them to divide by 1000 and use ecommerce platforms that can not really handle their currency (they typically place a Not sure, but I don't think it is worth converting the system to work with strings, maybe there are other options? |
I'm also quite against converting to strings. It might create huge problems... |
It might be crazy, but what about splitting the price into 2 columns, one for the whole number and another for the decimal part? It might come as a feature flag and/or a plugin. |
Like having a |
Thought about that as well, it would solve the problem for now (at least on 64 bit systems) it seems. Maybe a plugin would be better, because in most use cases you really don't need this. That way it's possible to try this out and see what the consequences are without being an integral part of the framework. |
If it is in a plugin, I'd require it to be compatible with MoneyBundle used in standalone. |
@Roshyo by having 2 fields I think there is no need to keep the price in hundredth or thousandth. |
@vvasiloi the original problem in this thread was : "Store currency in other rounding than hundredth" because of the above reasons. Simply exploding price in 2 columns and remaining the simple "2 digits after the coma" does not solve the original issue. Or I did not understand what you said |
@Roshyo if it will be stored in two columns, then there will be no need for rounding.
|
I'm afraid I don't understand your point. the decimal part is an int, ok, but the value of 1 unit has to be defined. At the moment 1 unit in |
Right, 10.50€ will be stored as 10 and 50 and the trailing zero will break the calculations. |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions. |
I am currently having an issue with roundig aswel. This makes the grand total inaccurate. A workaround could be applying the discount on the Order, but that causes issues with taxation. @Roshyo |
Integrating https://github.com/moneyphp/money might be a good idea. |
As a followup to my comment above: This can be seen in the Sylius docs: https://docs.sylius.com/en/1.6/cookbook/promotions/custom-promotion-action.html#create-a-new-promotion-action |
Sorry to ping to a stale issue, did you guys find out a solution for this issue? Is moneyphp really a viable solution? |
@mbabker I saw this https://github.com/BabDev/MoneyBundle recently and I was wandering if you used it with Sylius? |
Not with Sylius, no. If you're looking to move toward https://github.com/moneyphp/money then my bundle definitely helps with that integration, plus it provides a few extra features (i.e. serializing |
Thanks! I'm not yet actively looking to do that, but maybe one day... |
I'm also having rounding problems, with euro currency. I've put an eCommerce solution online that sells small plastic parts (so almost every product has cents in its price). If I apply promotions, the rounding error kicks in when there are significant cents at play: Example: if I buy 20 items, the item total will be 23.00€ and the discount 2.3€ <- correct When the error is present the order total is often correct nonetheless (the rounding error is too small to be taken into consideration), in other cases it will be wrong by some cents. In the admin panel it's often wrong in the two columns displaying "discount" and "discounted price", as per output of "getDiscountedUnitPrice" and "getFullDiscountedUnitPrice" functions in OrderItem, which can lead to confusion when reviewing the order, because it makes it look like that discountedUnitPrice*quantity is different from the orderItemTotal Here, as an example with a 10% promotion, the discount is calculated as 0.13 even tough is should be precisely 0.12. The discounted unit price is then wrongly calculated as 1.07 but, weirdly, the subtotal "is correct", in the sense that it's calculated as 1.08*20 (almost...in fact it should be precisely 21.6)...it's not a big issue but indeed a scary one potentially |
Describe the proposed solution
At the moment, Sylius is storing currencies in hundredth of currency. That's a really good point for all the reasons we all know. But it should be allowed to store currencies in thousandth or ten thousandth or whatever we want to.
To do so, at the moment we have to override some files like MoneyType, MoneyFormatter at least.
It should be nice if we just had to change a configuration parameter in yml to change this rounding so that we have a better configuration.
The main use case I see is for side projects that needs to store an exact amount that might itself be rounded from an other one. And the hundredth rounding mode might lose some informations at this point.
Describe alternatives you've considered
I don't see any other alternative than overriding previously given files.
Additional context
The text was updated successfully, but these errors were encountered: