-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.7] Add decimal:<num>
cast to Model
#26173
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm. Can you fix the StyleCI failures though?
@@ -718,7 +718,7 @@ public function fromFloat($value) | |||
} | |||
|
|||
/** | |||
* Return a decimal as string | |||
span class="pl-s1"> * Return a decimal as string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, I just experienced this bug as well with the new suggested changes feature from Github. It's still very beta :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:( Will do it manually :)
Can you please add a test? |
@staudenmeir Added some tests! |
I think this should be marked as a breaking change, i had to change al models using decimal cast. |
There was no |
Hmm strange i used it in my application for quite some time. Don't know how i get it in there in if it did anything tough. |
Great addition. I think it should allow to set $dec_point and $thousands_sep for number_format. In languages like german a comma is usually used for $dec_point. Or maybe these two variables could be set as a config value somehow. |
Italian has the same problem: it uses dots as thousands separators and commas as decimal separators. However, I think it's ok to hardcode those defaults, because both PHP and SQL follow the US notation anyway. |
The current implementation follows the output from MySQL, so dots for decimals and no thousand seperators. If you want to format it for invoices etc, you should probably do that last. Otherwise you can't calculate etc with it. |
Adds a
decimal
cast, to cast to a string with a set number of decimals. This makes it easier to preserve the type when updating the value and makes theisDirty()
check work.A
decimal
field is already returned as string when getting it from the database. Simplified example:Old behavior:
This will allow to add this cast to the model:
In the example it will now always output
(string) "2.00"
and is no longer dirty.Fixes #13742