locked
Dynamically set culture for date format but keep currency USD RRS feed

  • Question

  • User-1028151323 posted

    OK, I'm successfully changing cultures on the fly, working fine. I needed this for date formatting, but that's ALL I need it for. Unfortunately its also changing currency, which I do NOT want it to do. I need currency to display in USD at all times.

    Here's what I've got, can anyone shed some light on how I keep the currency formatting in USD?

    <!-- Start block. Created with Code4Blog for Microsoft Visual Studio 2010. Copyright (c)2010 Vitaly Zayko http://zayko.net -->
     public void SetCulture(string cult)
             {
                 if (!String .IsNullOrEmpty(cult))
                 {
                     var selectedLanguage = cult;
     
                     Thread .CurrentThread.CurrentCulture = CultureInfo .CreateSpecificCulture(selectedLanguage);
                     Thread .CurrentThread.CurrentUICulture = new CultureInfo (selectedLanguage);
                     var dtfi = (DateTimeFormatInfo )Thread .CurrentThread.CurrentCulture.DateTimeFormat.Clone();
                     Thread .CurrentThread.CurrentCulture.DateTimeFormat = dtfi;
                     Thread .CurrentThread.CurrentUICulture.DateTimeFormat = dtfi;
                 }
     
             }
     
    <!-- End block -->
    Wednesday, June 27, 2012 10:55 AM

Answers

  • User-1028151323 posted

    OK, I've found a way to set this at the string level:

    .ToString("C2", CultureInfo.CreateSpecificCulture("en-US"))

    I'll proceed using this unless I find a way to do it where I'm setting the culture

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 27, 2012 11:25 AM