In a current project of mine I have a decimal column in my Database stores something such as 1.9.9 current the column type of number does not support that and comes back with an error:
"A non well formed numeric value encountered (View: /Users/abby/Sites/cord/vendor/backpack/crud/src/resources/views/columns/number.blade.php)"
yes I suspected that since its not really a number.. but some may consider it a number since it kind of is (ie: version number) should we add a check and allow for decimals in version, or maybe just in the documentation have a link that says "decimal" and directs them to just text with a notice saying to use that?
I really don't think 1.0.1 it's a decimal number. .. more of a float?
Sorry if i'm wrong...
A Sex, 1/06/2018, 03:01, Abby notifications@github.com escreveu:
In a current project of mine I have a decimal column in my Database stores
something such as 1.9.9 current the column type of number does not
support that and comes back with an error:"A non well formed numeric value encountered (View: /Users/abby/Sites/cord/vendor/backpack/crud/src/resources/views/columns/number.blade.php)"
yes I suspected that since its not really a number.. but some may consider
it a number since it kind of is (ie: version number) should we add a check
and allow for decimals in version, or maybe just in the documentation have
a link that says "decimal" and directs them to just text with a notice
saying to use that?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Laravel-Backpack/CRUD/issues/1437, or mute the thread
https://github.com/notifications/unsubscribe-auth/AG2uv4F2zfSmiCKGH6ppOSdNik6vf-bdks5t4KB8gaJpZM4UV_Ad
.
Correct that it is a float, It was simply an example as my field is basically a "version" number. feel like mixing it into the number as it is only a single attribute that needs to be added to the number field type:
step="any"
If you just want to only allow positive numbers it would be step="0". I would like to maybe see us set the default of step to 0 to only allow positive numbers but also have an option when adding the field to set a custom variable for step to cover all situations.
I haven't had a chance to get to a PR yet, but wanted to see if anybody else thought this was worth while?
The step attribute specifies the legal number intervals for an element. Example: if step="3", legal numbers could be -3, 0, 3, 6, etc.
To validate positive numbers we should add:
min=0
To validate decimal numbers we should add:
step=0.1 or step=0.01
Maybe two attributes on number field like:
$this->crud->addField([
'name' => 'name',
'type' => 'number',
'step' => '1',
'positive' => true
]);
Thanks hope it helps,
Pedro
Adding the positive option seems pointless since “step” needs to be 0 or greater to require that. Step being able to set to whatever you want is the best scenarior. If you want negative you can put any, want 2 points just set it to 2.
1.0.1 or any other version STRING is not a number; we just call it that.
Let's not try to change the rules of mathematics or language here.
:))
@AbbyJanke - i found a really clever solution to this. I was in a situation where i couldn't alter all the records.
I found a stackoverflow response that provided me with a function that i can reuse and so, i've turned that into an accessor that i can safely reuse.
Anyways, i'm posting this here as i'm sure people have encountered this (or will encounter it) in the future as i'm sure @tabacitu knows that romanian prices are strange :)
Here's the accessor that i shamefully _borrowed_ from the above stackoverflow response:
public function getColumnAttribute($value, int $precision = 2)
{
$input = str_replace(' ', '', $value);
$number = str_replace(',', '.', $input);
if (strpos($number, '.')) {
$groups = explode('.', str_replace(',', '.', $number));
$lastGroup = array_pop($groups);
$number = implode('', $groups) . '.' . $lastGroup;
}
return bcadd($number, 0, $precision);
}
Thanks for sharing your solution @niladam !