Closed alessandromorelli closed 10 months ago
Hi, the problem is that there are many locales, and that some of them use the comma ,
as a thousand separator:
So I believe this method should stay locale-agnostic, and that you should create your own parser for this use case!
Hi, yes, I thought about that, but as the method already forbids thousands separators in the integral part, allowing either as a decimal separator would not generate ambiguity in parsing.
Next option is to allow specifying the separator as an optional parameter to the ::of
method, but IMHO it’s not worth the trouble.
Best option would be to have a function to parse a numeric string in its parts, like numberformatter::parse
, but that would mean non-userland code.
This change could be a good and useful compromise.
as the method already forbids thousands separators in the integral part, allowing either as a decimal separator would not generate ambiguity in parsing.
I don't agree: 1,234
could mean either 1234
or 1.234
, depending on the source of the data. I think accepting multiple separators just adds to the confusion. The dot is the standard decimal separator for programming languages, I think that brick/math should support this and nothing more, for the same reason it doesn't accept any thousands separator.
Your use case belongs to a locale-aware number parser, which would be at best a nice addition to brick/math (in a separate class), or even better, a separate package.
Closing due to lack of feedback.
master
The
BigNumber::of
method is not locale-aware and only accepts a period as a decimal separator.I propose to allow either a period or a comma as decimal separator, as it would cover all practical use cases, regardless of locale.