culture

Decimal symbol issue in MVC, C#?

旧街凉风 提交于 2019-12-08 00:51:33
问题 I'm using MVC 5.0 I set the culture in config: <system.web> <globalization uiCulture="fa-IR" culture="fa-IR" /> </system.web> I have a model as the following: public class MyModel { [DisplayName("NbatPersent")] [Range(0, 100)] public double NbatPersent{ get; set; } } MVC shows the NbatPersent value in View like 22/5 and when I wanna submit form the form validator alert me The field NbatPersent must be a number. . It can't convert 22/5 to 22.5 It will be OK if I enter 22.5 but if the property

Convert number into culture specific

房东的猫 提交于 2019-12-07 22:31:29
I have a number like 202667.4 . I want to convert this to number based on culture . For Ex: In "de"(German) the number should be in 202.667,40 . Any help will be greatly appreciated. Thanks. If you want to represent existing number (say, double ) in culture specific format, try formatting : https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings double source = 202667.4; // "n" - ... group separators, and a decimal separator with optional negative sign // "de" - German culture string result = source.ToString("n", CultureInfo.GetCultureInfo("de")); Console

asp.net mvc where to set default culture?

前提是你 提交于 2019-12-07 09:58:56
问题 For multilingual asp.net mvc web site. Where should i set thread's culture to default language (which is tr-TR for my case), in addition i need to save this in cookie if it does not exists. in Application_Start() or else ? I have multiple sites(domains), so i need to change default language site specific. example.com must set default culture to tr-TR example2.com must set default culture to en-US 回答1: Try it setting in web.config <configuration> <system.web> <globalization uiCulture="en-GB"

Decimal symbol issue in MVC, C#?

半腔热情 提交于 2019-12-06 16:02:20
I'm using MVC 5.0 I set the culture in config: <system.web> <globalization uiCulture="fa-IR" culture="fa-IR" /> </system.web> I have a model as the following: public class MyModel { [DisplayName("NbatPersent")] [Range(0, 100)] public double NbatPersent{ get; set; } } MVC shows the NbatPersent value in View like 22/5 and when I wanna submit form the form validator alert me The field NbatPersent must be a number. . It can't convert 22/5 to 22.5 It will be OK if I enter 22.5 but if the property has a value it convert . to / How can I convert all numeric properties' culture to en-US to show value

Currency Culture Formatting not applying on DataGridView Column

情到浓时终转凉″ 提交于 2019-12-06 14:21:20
I have 2 DataGridViews (DGV), and in both I have currency columns which I want to format. The code I'm writing seems to work in one, but not in the other. Both the DGV's are set up this way: Data is first loaded into a DataTable. A BindingSource then links to this DataTable. And lastly the DGV's use this BindingSource object for their data. I use the following code in the form's Load event to customize both DGVs' currency columns: dataGridView.Columns[columnIndexHere].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("de-DE"); dataGridView.Columns[columnIndexHere].DefaultCellStyle

Opposite method to toLocaleDateString

本秂侑毒 提交于 2019-12-06 13:50:12
问题 In order to create a string that respects the browser culture, we can do: var myDate = new Date(); var myDateString = myDate.toLocaleDateString(myDate); //returns a string Which is nice, because if I'm in Portugal, for the 1st of June, this will output "01/06/2015", while if I'm on the states, it will output "06/01/2015". Now I want the exact opposite. I want: var myDateString = "01/06/2015" var myDate = myDateString.toLocaleDate(); //it should return a Date Any suggestions? 回答1: Browsers

how to handle culture in double parsing in c#?

十年热恋 提交于 2019-12-06 11:09:08
I have a question about how to handle culture while parsing doubles. In a system price information from various servers comes together. However the data thats given as input varies in culture. two million and fifty cents is given as : "2.000.000,50" "2,000,000.50" "2000000.50" "2000000,50" is there a generic way to handle these various types of input ? Sriram Sakthivel No, there is no generic way. You either need to know what culture the double was formatted or all the servers need to send in a single format, say InvariantCulture . If you guess the culture, there's a bad news waiting for you

How to map a two letter ISO-3166 country code to a Culture in C#

假装没事ソ 提交于 2019-12-06 06:05:55
I need to localize my C# DateTime object based on a two letter ISO-3166 country code https://en.wikipedia.org/wiki/ISO_3166-2 Is there a way to do it? I'm only able to apply a given culture using the 5 character country representation (en-US, nl-NL and so on..) System.Globalization.CultureInfo cultureinfo = new System.Globalization.CultureInfo("nl-NL"); DateTime dt = DateTime.Parse(date, cultureinfo); Even a surjective mapping would be ok (i.e. more than one country code map to a single C# culture) From CultureInfo(string) constructor documentation; For a list of predefined culture names, see

DateTime supported language for formatting?

一曲冷凌霜 提交于 2019-12-06 06:04:05
DateTime let you format depending of the current culture. What are the culture supported by default? The scenario I have in mind use this.Date.Value.ToString("MMMM") which will print "January" if the culture is set to english-us but will print "Janvier" if the culture is in french-ca. This formatting documentation can be found at MSDN website but doesn't give the scope of culture this one can translate. I would like to know what languages are supported and if a language is not, what are my options? You can use CultureInfo.GetCultures to get all supported cultures. CultureInfo[] cultures =

JavaScript: Format number/currency w/regards to culture like .NET's String.Format()?

最后都变了- 提交于 2019-12-06 04:50:51
问题 This seems like a problem someone would've already solved in the year 2009, but I can't find a decent JavaScript library that will take a number like: 12345.58 And format it correctly based on a specific culture (ie, "nl-nl") or ISO currency code. dojo showed promise, but it doesn't include many cultures by default, and actually wasn't working properly in my tests. I basically want something that is 100% or near-100% equivalent to what .NET does for me, when I run: String.Format([cultureInfo