I have an app which seems to work fine for me (and most users) but rarely on other systems (mostly outside US ones) the comma used for dollar values is considered a dot, cutting off the amount added.
For example, a player wins $5,500 and gets that added to their total. On one test system (in Hungary), they get $5 instead. I would like code that would make this value get added properly regardless of regional differences.
For example, the code I use:
storsal = y
cash = cash + storsal
The variable ‘storsal’ and ‘y’ are dimmed as an integer, and yy is a String. The first line should strip the $ and commas so it gets added as a whole number, I think.
Can someone tell me a foolproof way to do this?
a/ Dont store the $
b/ STORE and CONVERT using Val() and STR()
c/ to display, use CSTR() and to read from display back into a double, use CDBL()
A value of 123456.78 is held in a double inside your app
Display it using CSTR()
In America you see 123456.78
In France you might see 123.456,78
If someone types 1.23 on screen in America, they would have typed 1,23 in Hungary
To get both of those to work in your app, use CDBL() and they both turn into 1.23 in a double.
You get the right amount of money in both countries.
Store doubles in a database.
If you want to store the money in a text file, always save it and read it in American format, no matter where you are.
If an app stores floats as text in local format, switching locales and sharing the files can cause unexpected bugs.
Been there, bitten by that, solved it this way.
Maybe the OP won’t store values as strings in local format.
But maybe someone else was thinking of doing so.
Well, I would guess that doing it this way keeps compatibility within your app between different locales.
However the downside to me seems that you loose compatibility with other apps which use the correct locale (importing a table into Excel where the date format is wrong or the thousand separator seems like a receipt for desaster).
In my opinion compatibility with other apps on your computer is MUCH more important then compatibility with other users of your app living in different countrys.
How do Apple and Microsoft deal with this? Store the locale in the file?
BTW: do you know that 2018 is not the year number for eveybody in this planet ?
Some are in theyr 14xx, some others in their 67xx, etc. And I do not talk about India where many different year numbers exists in the same country.
Because if you are in Europe and save in US format (eg MMDDYY) but want to open the data in another app on your computer (which uses the locale and expects DDMMYY) then you are in trouble.
But if you save in EU format and send it to someone in the US then you again run into problems.
According to Tim the first way is a standard which I find doubtful as data exchange with other apps on your computer and other users in your country is far more prevalent than data exchange with users in other countries.
Microsoft Excel… Maybe they’ve done that for Number/Date values in cells - but they certainly haven’t done it for cell Formulas.
So for example a cell with Formula =SUM(A1:A2) results in an error if you open an English document that uses this simple formula with Excel running in German.
There’s no single and correct answer… there is both good and bad from both big and small developers/companies out there.