Click here to Skip to main content
15,910,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I making an app with C# and data stored in a file as decimal numbers. however, extracting these decimals giving a problem since I am working with two people which the first one has the English region and the other European region computer.
the problem is in the "decimal separator". the decimal number "3.466" as an example the English computer will read it as 3 with a fraction of 0.466 but the European region will read it as 3466 as a "three thousand four hundred and sixty-six". I had to change the file to the comma separator ",".
the "." is a thousand separator in the European region PC and vise versa in English PC.

how to unite these in such it does need to change the whole file for data. also when finish the app need to change the file for each region. if accidentally download the wrong region the app will not work properly.

any type of idea what code to solve this problem

What I have tried:

I change the file of data one to "." and other to "," separator manually for each region
Posted
Updated 30-Nov-20 11:07am
Comments
Maciej Los 30-Nov-20 16:47pm    
Have you ever heard about Globalization[^]?
PIEBALDconsult 30-Nov-20 18:10pm    
Use JSON. Done.

1 solution

The various TryParse methods have optional overloads which support culture. For example: Double.TryParse Method (System) | Microsoft Docs[^]
If your app uses TryParse to try and read the value in European format and fails, it can retry using the UK format and see if that works.

But a better solution is not to store data in "human readable" format at all: read values in local format, convert them to numeric values, and store them as numbers. That way, the stored data is "culturally agnostic" and can be displayed or input in whatever local format is selected by the computer user.
Storing it in "local" format is a bad idea and should be stamped on, and out!
 
Share this answer
 
Comments
Member 12224804 1-Dec-20 7:54am    
so better to convert to numerics as example hours min and seconds ?
OriginalGriff 1-Dec-20 8:23am    
Where do hours, minutes and seconds come into it? There are none in your original post!

Store them as numbers: write them as binary values to a file and read them back as binary values. Or use XML, JSON, something that is culturally agnostic.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900