none
NumberFormatInfo.CurrentInfo returns wrong value for NumberDecimalDigits RRS feed

  • Question

  • Hi Team,

    The property NumberFormatInfo.CurrentInfo(read-only) returns wrong value for NumberDecimalDigits with my ASP.Net application, but works correctly in my console application. Actually I have changed the property "No. of digits after decimal" property in Windows Control Panel from "2" to "9". It still returns 2 in my ASP.Net application whereas it returns 9 correctly in my Console application. Please help me on this.

    Thursday, December 12, 2019 12:19 PM

All replies

  • Have you checked which culture is current

    System.Threading.Thread.CurrentThread.CurrentCulture
    System.Threading.Thread.CurrentThread.CurrentUICulture

    Perhaps from that you might know what is going on.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Thursday, December 12, 2019 3:10 PM
    Moderator
  • Maybe you've already thought about this, but remember that an ASP.Net application will be using the attributes of the system where the web server runs, not the system viewing the web page.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Friday, December 13, 2019 1:12 AM
  • Maybe you've already thought about this, but remember that an ASP.Net application will be using the attributes of the system where the web server runs, not the system viewing the web page.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    I am using the web page from my server machine but it does not return the exact value as it should.

    Friday, December 13, 2019 4:04 AM
  • Have you checked which culture is current

    System.Threading.Thread.CurrentThread.CurrentCulture
    System.Threading.Thread.CurrentThread.CurrentUICulture

    Perhaps from that you might know what is going on.


    I am not getting the expected value both in CurrentCulture and CurrentUICulture
    Friday, December 13, 2019 4:05 AM
  • Consider a custom culture and number format. The next example writes a number using default and custom format:

    // Display 'f' using current number of decimals (2):

     

    double f = 123.456;

    Console.WriteLine( "{0:N}", f ); // "123,46"

     

    // Display 'f' using custom culture with 9 decimals:

     

    CultureInfo ci = CultureInfo.CreateSpecificCulture( "en-US" );

    ci.NumberFormat.NumberDecimalDigits = 9;

    CultureInfo.CurrentCulture = ci;

    Console.WriteLine( "{0:N}", f ); // "123.456000000"

     

    In this case you can define a specific language and formatting options based on preferences of the current Web user that accesses your ASP, which is convenient in case of global Web sites.

    You can also control the number of displayed decimals using various formatting functions, such as f.ToString(“N9”).


    • Edited by Viorel_MVP Friday, December 13, 2019 6:32 AM
    Friday, December 13, 2019 6:25 AM