At start-up of an application you should always set the desired CultureInfo to the running thread to avoid wrong formatting of DatetTime and Number information in your application. Especially if you need custom formatting ... because by default, the running thread takes the culture settings of the machine it is running on. In the example below I set some custom fixed formatting options for DateTime and numbers. Afterwards I assign this cultureInfo to the CurrentCulture of the current thread.
As a result, the ToShortDateString method on the DateTime object will always display the DateTime information in the desired format. Also the number formatting for the decimal is like it should be. Note that I must pass the numeric format N to the ToString method so that the decimal will be shown as a number. More information about standard numeric format strings at MSDN.
If you need formatting that deviates from the default formatting specified in the current thread, you can still specify a custom FormatProvider in the ToString method.
My advice : do not create your own custom formatting/conversion functions in your applications, but try to keep it simple and use the stuff that's already available in the .NET Framework (CultureInfo class)!
One extra remark on cultures on the CurrentThread :
- CurrentUICulture specifies the culture for the user interface and is used for resource file lookups.
- CurrentCulture specifies the culture for data and information. It is used to format dates, numbers, currencies and sort strings.