You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Types::Params::Float and Types::Params::Decimal should coerce number parameters with comma as decimal separatotor (eg "12,34")
ISO8601 allows using comma "," or full stop "." as decimal separator. Of these, the comma is the
preferred sign
The text was updated successfully, but these errors were encountered:
We could add support for this as either a separate type or based on additional configuration. We need to use regexps to check the format and that is very slow, that's why this should be an opt-in behavior.
I know that I can define my own type that does it, but as I understand Params category of dry-types is intended for HTTP params processing which is often user input. I think it could be supported by default as roughly half of the world will write decimal/float numbers wit comma as separator and it is even in ISO standard.
If you need performance than you can just use Types::Coercible::Decimal or Float.
May be you don't even need regexp, you might just try Float(input.tr(',', '.')) if input is a String.
One of the reasons why dry-types was created was to remove generic coercions. We want coercions to be as narrow as possible in order to avoid situations where something is coerced by a mistake or incorrectly. I think people should be 100% clear regarding the number format they want to support and we should have types that make supporting various formats as simple as possible. For instance I would define validation rules for formats that my system is supposed to support and have corresponding coercion types (if needed). This way you remove any ambiguity from your coercion/validation layer.
We can really make this quite simple for the users. ie we could add predefined coercion types that we could access by country identifiers or some other identifiers that could be understood by people. What we should not do is blindly assuming that the comma is used in one way or the other.
Types::Params::Float and Types::Params::Decimal should coerce number parameters with comma as decimal separatotor (eg "12,34")
ISO8601 allows using comma "," or full stop "." as decimal separator. Of these, the comma is the
preferred sign
The text was updated successfully, but these errors were encountered: