Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6843737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:17:16+00:00 2026-05-27T00:17:16+00:00

I have a .NET app that allows a user to choose their own language

  • 0

I have a .NET app that allows a user to choose their own language & culture (date/number formatting). Their culture setting is stored in Thread.CurrentThread.CurrentCulture (also Thread.CurrentThread.CurrentUICulture, but that’s a separate issue).

When I print out a var via Razor, it shows in localized format:

<span>@bignum</span> (renders as "123.456" or "123,456")

However, I also need to pass some .NET vars to Javascript:

var js_bignum = @bignum;

The problem is that Javascript in this case does not understand the localized versions of these numbers, so it fails since the above statement becomes:

var js_bignum = 123,456;

It may be because the user’s browser’s culture setting is different from the user’s webapp’s culture setting. At any rate, it’s a situation we need to be able to handle.

So what’s the easiest way to handle this? I can create my own Javascript ConvertToStandardNumberFormat() that takes a string value from .NET and returns a “standard” number format, but that seems like a bit of a hack. Is there a way to force .NET/razor to render a non-localized format number?

var js_bignum = @price.ToUnlocalizedFormat();  (Is there something like this?)

I’m just trying to figure out what the best practices are for this type of situation.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:17:16+00:00Added an answer on May 27, 2026 at 12:17 am

    I would use @price.ToString(CultureInfo.InvariantCulture)

    Edit

    I have to disagree with João answer and would consider it a Bad Idea™. I would not recommend re-inventing the wheel. If you would prefer a more comprehensive approach, then I would opt to include a dedicated C# JSON encoding library (I would recommend JsonFx.NET).

    The most simple approach, I would make an HtmlHelper extension. Something like:

    public static class JsonExtensions {
         public static string ToJson(this HtmlHelper html) {
             return new JsonWriter().Write(t);
         }
    }
    

    Then use it in a view with:

    @Html.ToJson(price)
    

    This should handle primitive types as well as complex types.

    After that I would probably refactor things and try to come up with a better injection pattern so that I’m not creating a new JsonWriter with each call to the helper.

    But this will be much more flexible (and tested) than rolling your own serializer in the form of a static helper class…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a non-SSL ASP.NET web app that allows a user to login (ASP
I have an app that allows a user to use JQuery and Javascript to
I have an asp.net mvc app with a route that allows users to request
We have a NET app that gets installed to the Program Files folder. The
I have this .NET web app that draws a table in Page_Load. Then after
I have a .NET client app that intermittently loses connection to a UNC share
I have an ASP.NET app that sits on our intranet, using the WindowsIdentity to
I have an asp.net app that uses System.IO.Path.GetTempFileName() for temporary files. In the production
I have a .Net 2.0 app that is used internally and we want to
I have an ASP.NET MVC app that opens a Request view in a new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.