#1,116 – An Example of Output that Obeys CurrentCulture

The first step in internationalizing an application is to respect the current regional settings when outputting numeric, date/time, or currency values.

Below is an example of an application that displays numeric and date/time values, using the ToString method for instances of double and DateTime.

        <StackPanel Margin="10" Orientation="Horizontal">
                <Label Name="lbl1"/>
                <Label Name="lbl2"/>
                <Label Name="lbl3"/>
                <Label Name="lbl4"/>
                <Label Name="lbl5"/>
                <Label Name="lbl6"/>
                <Label Name="lbl7"/>
        <Button Content="Gen Strings" Padding="10,5"

In the Click event handler, we set the labels’ content.

        private void Button_Click(object sender, RoutedEventArgs e)
            DateTime rightNow = DateTime.Now;

            lbl1.Content = rightNow.ToString();
            lbl2.Content = rightNow.ToString("d");  // short date
            lbl3.Content = rightNow.ToString("D");  // long date
            lbl4.Content = rightNow.ToString("t");  // short time
            lbl5.Content = rightNow.ToString("T");  // long time

            double num = 123456.789;
            lbl6.Content = num.ToString();
            lbl7.Content = num.ToString("n");

With regional settings set to English (United States), the output looks like this:


If I change my region to French (France), the formatting changes as expected.




About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #1,116 – An Example of Output that Obeys CurrentCulture

  1. Pingback: Dew Drop – July 17, 2014 (#1816) | Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: