How to get default decimal / thousand separator for current locale in .net
Asked Answered
S

3

5

I need thousand and decimal separator as per current culture. If we are using US culture then for decimal it should '.' and for thousand it should ','. But for German culture default decimal separator is ',' and thousand separator is '.'. for getting date time separator I am using following code

               CultureInfo us = new CultureInfo("en-US");
                string shortUsDateFormatString = us.DateTimeFormat.ShortDatePattern;
                string dateseparator= us.DateTimeFormat.DateSeparator;
                string timeseparator= us.DateTimeFormat.TimeSeparator;

Is there any way something same like date / time ?

Scar answered 2/9, 2015 at 4:47 Comment(3)
Search for title bing.com/… gives MSDN link among top results... You really should consider to pick better search engine that you are using.Oligoclase
@AlexeiLevenkov, Your link only gives the data type, still need to request it from somewhere and that is the important part (hence the NumberFormat below). Maybe the search engine comment is unjustified :)Karylkarylin
@AlexeiLevenkov heh, Google brought me here, and the first (and accepted answer) is correct anyway. :-)Konikow
E
8

The NumberFormat property has this info for both Currency and Numbers.

Eury answered 2/9, 2015 at 4:54 Comment(0)
F
7

You can use the NumberFormat property of the CultureInfo which includes properties for the decimal separator and thousands separator

var numberFormat = us.NumberFormat;
string decimalSeparator = numberFormat.NumberDecimalSeparator;
string thousandsSeparator = numberFormat.NumberGroupSeparator;
Fashion answered 2/9, 2015 at 4:56 Comment(0)
P
6

By this code can get the current system settings :

System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
FORMAT_NUMBER_DECIMALSEPARATOR = ci.NumberFormat.CurrencyDecimalSeparator;
FORMAT_NUMBER_DIGITGROUP = ci.NumberFormat.CurrencyGroupSeparator;
Penstock answered 2/9, 2018 at 14:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.