I recently realized that some countries display floating point numbers with different comma/period notation.
ie. we would have 12,500.34, and some countries would list it as 12.500,34
This may not be a problem with display, but what about text input? For example, I imagine that if I had a decimal type and displayed it in a label, that the ToString() method (or equiv in your language of choice) would use the localization settings and display it properly, and the various parsing ‘str->number’ methods would probably work too.
But what about text validation? Like say I want a textbox to only allow 5 numbers, and then an optional decimal point and up to 4 more numbers? What is a common solution is this case, when you don’t know what their delimiters will be? Obviously the hardcoded regex patterns i’m using now will fail, so I’m just wondering what some of you have done in these cases?
thanks for any advice
Where ever they live or however they’re specified, you need to encapsulate rules that are or can be locale specific or are parsing inputs (for validation) that could be locale specific. This way you can switch the implementation out based on locale.
Depending on how and where these are you can use some frameworks (JPF does this) to apply within a framework or you can also extend your framework to work with them.