Stored Number with dot but display with comma in frontend - c#

The data type in database is "decimal", the value is normally like 2.6, 3.8 etc
But when I render it on the front side, it become 2,6
I wondering why it happens and how to handle it correctly.
I try to adjust .Net Globalization Culture in IIS become EN, then display as I want.
Not the setting is Invariant Language.
I had print out culture info by C#, it shows GB
How can I handling it as all display number with dot

Related

Multi lingual site for one country

I have a requirement where I have a site and the user enters the product information from an administrative end.
One of the mandatory requests is to select a country for the product before the user can save the product.
When a public user arrives at the site they need to have the option to swap between the languages. So if I arrived to the German site and want to view the site in English I should be able to change from German to English (and back to German).
I have the resource files created (German) however how do I swap between the two languages. I appreciate I may need to tweak a little more but if I can get onto the right track I can take it/question from there?
First you ensure you save the data in the correct encoding in your database by configuring the data collation for each language, and save it in the correct datatype.
To do that you must do the following :
Database
Ensure the column or database collation is defined to the targeted language read more about it SQL Server, Oracle, MySQL
Ensure the column datatype is designed to accept Unicode characters. (if you save some text, it should show it as is).
Application
in your ASP.NET Application, you ensure that you read these data from the database with the correct encoding ( UTF-8 is a common encoding for the web, but sometimes you might need to use ASCII or Unicode then convert it back to UTF-8 depends on the language you're dealing with).
After ensuring the string encoding. You can now use it on your ASP pages, you only need to control the page language you have two options.
Option 1 : Use Javascript to translate the page to another language dynamically using html lang attribute.
Option 2 : Use .NET Globalization by defining the translations using resources files more in that in this link

Turkish Currency Symbol is being displayed as square

I have a asp.net mvc application which stores currency types in the database. Symbol for each currency is also stored in the db. Currency types are retrieved from the db and currency symbols are displayed in a dropdown in my application.
In my development machine all of the currency symbols are displayed properly in the dropdown. But in the production machine, turkish currency symbol is displayed as a square for the same dropdown. Both environments have the same symbol in the db. And this symbol is retrived from database and presented without any modifications all the way to the browser.
My development machine is set to United States format, production machine is set to Swedish format. So I initially thought the problem was because of that, but when I change the system format to swedish in my dev machine, I couldn't reproduce the problem.
Another difference between the environments is the .net version, they are slightly different, but it is less likely to be the root cause of the issue.
I am running out of ideas, can somebody guide me the right direction?

Preventing Cyrillic/Greek/Chinese in a string - C# 4.0

We have a system (using ASP.NET C# 4.0) that supports Greek, Cyrillic, Chinese characters. But a third party system doesn't seem to work correctly. To avoid issues when entering data for this third party system, I want to limit the text fields to accept only English or accented characters, but return a validation error for other characters.
How can I accomplish this? It seems I can use a regex along the lines of \p{Latin}, but C# doesn't seem to support this from my experience, as I get an Unknown property 'Latin' error.
In .NET, the Unicode block properties need to be written with Is...:
[\p{IsGreek}\p{IsCyrillic}...]
A pattern like this would detect all offending characters in your case. If you just want to exclude everything but Latin, you could do something like:
[^\p{IsBasicLatin}\p{IsLatin-1Supplement}\p{IsLatinExtended-A}\p{IsLatinExtended-B}]
This covers all code points up to U+024F.
For a list of supported block names, see MSDN.

C# program stops working after the language setting in control panel is changed (say, from English to German)

I have a software developed in C#, which is a pure sentefic application. Howver the German users found this software stopped working from time to time, when it is installed on German computers. The temporary solution is to change the Language setting in the control panel, and it works fine after we change the language setting from German to English. This is just a kind of engineering sofware, and the software have nothing relalted to the German or English language. Also, as suggested from other posts in msdn, I have checked the "InitializeComponent()" in the source does several times. There are not strange codes in the "InitializeComponent()" function.
When you change locale, you change the meaning of ',' (comma) and '.' (full-stop) when used in numbers. Could it be that you are trying to parse text containing these characters into numbers?
Does your program attempt to initialize numeric fields with formatted numbers, perhaps?
You need to make sure that your code is sensitive to the user's culture when parsing and formatting text. You also need to make sure you use a consistent culture (e.g. the InvariantCulture) when reading data stored to file or sent over a network.
If you are using .NET Framework 4.5, you might be interested to read about the CultureInfo.DefaultThreadCurrentCulture Property.
In the .NET Framework 4 and previous versions, by default, the culture
of all threads is set to the Windows system culture. For applications
whose current culture differs from the default system culture, this
behavior is often undesirable.
The examples and their explanations on the page could be quite helpful for your issue.
Also, as a side note, try{...}catch{...} blocks are always welcome.

Phone number normalization: Any pre-existing libraries?

I have a system which is using phone numbers as unique identifiers. For this reason, I want to format all phone numbers as they come in using a normalized format. Because I have no control over my source data, I need to parse out these numbers myself and format them before adding them to my DB.
I'm about to write a parser that can read phone numbers in and output a normalized phone format, but before I do I was wondering if anyone knew of any pre-existing libraries I could use to format phone numbers.
If there are no pre-existing libraries out there, what things should I be keeping in mind when creating this feature that may not be obvious?
Although my system is only dealing with US numbers right now, I plan to try to include support for international numbers just in case since there is a chance it will be needed.
Edit I forgot to mention I'm using C#.NET 2.0.
You could use libphonenumber from Google. Here's a blog post:
http://blog.appharbor.com/2012/02/03/net-phone-number-validation-with-google-libphonenumber
Parsing numbers is as easy as installing the NuGet package and then doing this:
var util = PhoneNumberUtil.GetInstance();
var number = util.Parse("555-555-5555", "US");
You can then format the number like this:
util.Format(number, PhoneNumberFormat.E164);
libphonenumber supports several formats other than E.164.
I'm currently involved in the OpenMoko project, which is developing a completely open source cell phone (including hardware). There has been a lot of trouble around normalizing phone numbers. I don't know if anyone has come up with a good solution yet. The biggest problem seems to be with US phone numbers, since sometimes they come in with a 1 on the front and sometimes not. Depending on what you have stored in your contacts list, it may or may not display the caller ID info correctly. I'd recommend stripping off the 1 on the phone number (though I'd expect most people wouldn't enter it in the first place). You may also need to look for a plus sign or country code on the front of international numbers.
You can check around the OpenMoko website, mailing list, and source control to see if they've solved this bug yet.
perl and rails examples
http://validates-as-phone.googlecode.com/svn/trunk/README
http://www.perlmonks.org/?node_id=159645
Just strip out any non-digits, possibly using a RegEx: [^\d]
The only exception might be if you want to handle extensions, to distinguish a number without an area code but with a 3 digit extension, or if you need to handle international numbers.
What you need is list of all country codes and start matching your string first few characters against list of country codes to make sure it's correct then for the rest of the number, make sure it's all digits and of proper length which usually varies from 5-10 digits.
To achieve checking against country codes, install NGeoNames nuget which uses website www.geonames.org to get list of all country codes to use to match against them.

Categories