Remove leading zeros in Decimal type.#716
Open
gregoryloichot wants to merge 7 commits intocosmocode:masterfrom
Open
Remove leading zeros in Decimal type.#716gregoryloichot wants to merge 7 commits intocosmocode:masterfrom
gregoryloichot wants to merge 7 commits intocosmocode:masterfrom
Conversation
Fix a bug. I was possible to create Decimal like 00123. This Decimal could be edited to 100123, but could not be reedited to 00123.
splitbrain
requested changes
May 14, 2024
types/Decimal.php
Outdated
| { | ||
| $rawvalue = parent::validate($rawvalue); | ||
| $rawvalue = str_replace(',', '.', $rawvalue); // we accept both | ||
| $rawvalue = trim((float)str_replace(',', '.', $rawvalue), 0); // we accept both |
Member
There was a problem hiding this comment.
If my value is 1000 this will reduce it to 1.
echo trim((float) '1000', 0);
1
I believe casting the value to float should already do what you want.
echo (float) '00004440000';
4440000
Author
There was a problem hiding this comment.
I think you are right. I will change that.
types/Decimal.php
Outdated
| throw new ValidationException('Decimal max', (float) $this->config['max']); | ||
| } | ||
|
|
||
| // remove leading zeros |
Member
There was a problem hiding this comment.
this comment seems to be in the wrong place
| $rawvalue = trim((float)str_replace(',', '.', $rawvalue), 0); // we accept both | ||
|
|
||
| if ((string)$rawvalue != (string)(float) $rawvalue) { | ||
| throw new ValidationException('Decimal needed'); |
Member
There was a problem hiding this comment.
I am wondering. Shouldn't this already prevent the issue you're trying to fix?
Author
There was a problem hiding this comment.
Thanks for your comments.
I updated the code. Let me know if you have any comments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix a bug. It was possible to create Decimal like 00123. This Decimal could then be edited to 100123, but could not be edited back to 00123. This pull request remove the leading zeros.