[fpc-devel] ThousandSeparator
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Thu Nov 27 15:04:14 CET 2014
Frederic Da Vitoria schrieb:
> 2014-11-26 16:54 GMT+01:00 Hans-Peter Diettrich <DrDiettrich1 at aol.com
> <mailto:DrDiettrich1 at aol.com>>:
>
> 2) Formatted numbers, as enterd by the user (maybe by copy&paste
> from other applications), can have various encodings. Before a
> conversion into binary values I'd remove all unexpected characters,
> except for the last (rightmost) '.' or ',', which then becomes the
> decimal separator as expected by the decoding function (RTL provided).
>
>
> You mean that the first string to be converted to binary would
> automatically set the decimal separator?
No, my code would make no assumption about the format of strings edited
by the user.
> That would seem dangerous to
> me. What if the first string to be converted contained something like
> "11,000", does this mean 11000 with thousand separator = comma (which
> would be true in at least USA), or 11 with decimal separator = comma
> (which would be true at least in France)? I can't think of any way to
> choose automatically.
Okay, that would require more knowledge about the value kept in a
specific input field, for range checks or the like. As long as thousands
separators occur in the string, different from '.' or ',', they are
quite easy to identify.
> AFAICS, the code needs either to use the system
> settings or to be told explicitly by the developer. Even relying on the
> system settings may not be enough, because one may need to "import" data
> formatted with different national settings from the system's settings.
Right. When e.g. a CAD program is fed with sizes from an external data
sheet, it cannot be expected that the figures in that file change
together with the system language, and are converted between inch and
meter, temparatures between F and C ;-)
So it looks to me as a stupid idea, when the user changes such system
settings *while* such a program is running. Furthermore the use of
national formatting conventions for the exchange of values across
applications looks to me like another stupid idea. Would somebody expect
or even like it, when e.g. constant declarations are converted when
copied into an Lazarus editor, and the compiler would require that all
constants in source code conform to the current settings?
As mentioned in other contributions, the number formatting seems to be a
Windows specific problem. How to deal with imported numbers on other
platforms, with arbitrary settings per application?
After all a program could, when notified of such changes, ask the user
whether to continue or restart, or force an restart. Restart should be
safe, but when the user decides to continue, he must be aware of
possible problems. When the restart takes considerable time, the user
may learn that his behaviour is not very clever ;-)
DoDi
More information about the fpc-devel
mailing list