How to create a number formatter at application level to format numbers based on different culture?










3















I am trying to format numbers based on US base format.



Code :



var data = String.Format("0:n" + 2 + "", 7453215, new CultureInfo("en-US"));


enter image description hereOutput :



74,53,215.00


Now the problem is I have this line of code at so many places where I am displaying numbers based on different culture so i have to change everwhere.



Is it possible to create some kind of formatter and register it once,change at one place and everywhere that change is applied to format numbers based on culture?



Updated :



var data = String.Format(new CultureInfo("en-US"), "0:n" + 2 + "", 7453215); 


Now I am getting correctly formatted number as per US based format but I would like to create common number formatter at application level.










share|improve this question
























  • What exactly does this have to do with asp.net-mvc? And when you say displaying numbers, do you mean in a view?

    – user3559349
    Nov 12 '18 at 8:41











  • @StephenMuecke Yes this is related to displaying in view and my project is an asp.net mvc application hence i have tagged this question with mvc tag

    – Learning-Overthinker-Confused
    Nov 12 '18 at 9:50











  • When I execute your code the result is 7,453,215.00, not 74,53,215.00 (is that a typo i your question?). And its not clear why you are using .Format("0:n" + 2 + "",...) instead of just .Format("0:n2", ...). And is the culture the only thing you want to change

    – user3559349
    Nov 12 '18 at 9:55











  • @StephenMuecke I have updated question with correct code and now getting number properly formatted as per US based format but I want to create number formatter at application level so if tomorrow if any body come and say i would like to format number in xyz culture so that i need to change culture at one place only and not all the place where i have used the code mention in my question

    – Learning-Overthinker-Confused
    Nov 12 '18 at 10:01












  • One option would be to define the culture in your settings file (or in webconfig) (say named myculture) and then instead of new CultureInfo("en-US") you would use new CultureInfo("Properties.Settings.Default.myculture")

    – user3559349
    Nov 12 '18 at 10:09















3















I am trying to format numbers based on US base format.



Code :



var data = String.Format("0:n" + 2 + "", 7453215, new CultureInfo("en-US"));


enter image description hereOutput :



74,53,215.00


Now the problem is I have this line of code at so many places where I am displaying numbers based on different culture so i have to change everwhere.



Is it possible to create some kind of formatter and register it once,change at one place and everywhere that change is applied to format numbers based on culture?



Updated :



var data = String.Format(new CultureInfo("en-US"), "0:n" + 2 + "", 7453215); 


Now I am getting correctly formatted number as per US based format but I would like to create common number formatter at application level.










share|improve this question
























  • What exactly does this have to do with asp.net-mvc? And when you say displaying numbers, do you mean in a view?

    – user3559349
    Nov 12 '18 at 8:41











  • @StephenMuecke Yes this is related to displaying in view and my project is an asp.net mvc application hence i have tagged this question with mvc tag

    – Learning-Overthinker-Confused
    Nov 12 '18 at 9:50











  • When I execute your code the result is 7,453,215.00, not 74,53,215.00 (is that a typo i your question?). And its not clear why you are using .Format("0:n" + 2 + "",...) instead of just .Format("0:n2", ...). And is the culture the only thing you want to change

    – user3559349
    Nov 12 '18 at 9:55











  • @StephenMuecke I have updated question with correct code and now getting number properly formatted as per US based format but I want to create number formatter at application level so if tomorrow if any body come and say i would like to format number in xyz culture so that i need to change culture at one place only and not all the place where i have used the code mention in my question

    – Learning-Overthinker-Confused
    Nov 12 '18 at 10:01












  • One option would be to define the culture in your settings file (or in webconfig) (say named myculture) and then instead of new CultureInfo("en-US") you would use new CultureInfo("Properties.Settings.Default.myculture")

    – user3559349
    Nov 12 '18 at 10:09













3












3








3


0






I am trying to format numbers based on US base format.



Code :



var data = String.Format("0:n" + 2 + "", 7453215, new CultureInfo("en-US"));


enter image description hereOutput :



74,53,215.00


Now the problem is I have this line of code at so many places where I am displaying numbers based on different culture so i have to change everwhere.



Is it possible to create some kind of formatter and register it once,change at one place and everywhere that change is applied to format numbers based on culture?



Updated :



var data = String.Format(new CultureInfo("en-US"), "0:n" + 2 + "", 7453215); 


Now I am getting correctly formatted number as per US based format but I would like to create common number formatter at application level.










share|improve this question
















I am trying to format numbers based on US base format.



Code :



var data = String.Format("0:n" + 2 + "", 7453215, new CultureInfo("en-US"));


enter image description hereOutput :



74,53,215.00


Now the problem is I have this line of code at so many places where I am displaying numbers based on different culture so i have to change everwhere.



Is it possible to create some kind of formatter and register it once,change at one place and everywhere that change is applied to format numbers based on culture?



Updated :



var data = String.Format(new CultureInfo("en-US"), "0:n" + 2 + "", 7453215); 


Now I am getting correctly formatted number as per US based format but I would like to create common number formatter at application level.







c# asp.net-mvc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 9:59







Learning-Overthinker-Confused

















asked Nov 12 '18 at 8:30









Learning-Overthinker-ConfusedLearning-Overthinker-Confused

86521470




86521470












  • What exactly does this have to do with asp.net-mvc? And when you say displaying numbers, do you mean in a view?

    – user3559349
    Nov 12 '18 at 8:41











  • @StephenMuecke Yes this is related to displaying in view and my project is an asp.net mvc application hence i have tagged this question with mvc tag

    – Learning-Overthinker-Confused
    Nov 12 '18 at 9:50











  • When I execute your code the result is 7,453,215.00, not 74,53,215.00 (is that a typo i your question?). And its not clear why you are using .Format("0:n" + 2 + "",...) instead of just .Format("0:n2", ...). And is the culture the only thing you want to change

    – user3559349
    Nov 12 '18 at 9:55











  • @StephenMuecke I have updated question with correct code and now getting number properly formatted as per US based format but I want to create number formatter at application level so if tomorrow if any body come and say i would like to format number in xyz culture so that i need to change culture at one place only and not all the place where i have used the code mention in my question

    – Learning-Overthinker-Confused
    Nov 12 '18 at 10:01












  • One option would be to define the culture in your settings file (or in webconfig) (say named myculture) and then instead of new CultureInfo("en-US") you would use new CultureInfo("Properties.Settings.Default.myculture")

    – user3559349
    Nov 12 '18 at 10:09

















  • What exactly does this have to do with asp.net-mvc? And when you say displaying numbers, do you mean in a view?

    – user3559349
    Nov 12 '18 at 8:41











  • @StephenMuecke Yes this is related to displaying in view and my project is an asp.net mvc application hence i have tagged this question with mvc tag

    – Learning-Overthinker-Confused
    Nov 12 '18 at 9:50











  • When I execute your code the result is 7,453,215.00, not 74,53,215.00 (is that a typo i your question?). And its not clear why you are using .Format("0:n" + 2 + "",...) instead of just .Format("0:n2", ...). And is the culture the only thing you want to change

    – user3559349
    Nov 12 '18 at 9:55











  • @StephenMuecke I have updated question with correct code and now getting number properly formatted as per US based format but I want to create number formatter at application level so if tomorrow if any body come and say i would like to format number in xyz culture so that i need to change culture at one place only and not all the place where i have used the code mention in my question

    – Learning-Overthinker-Confused
    Nov 12 '18 at 10:01












  • One option would be to define the culture in your settings file (or in webconfig) (say named myculture) and then instead of new CultureInfo("en-US") you would use new CultureInfo("Properties.Settings.Default.myculture")

    – user3559349
    Nov 12 '18 at 10:09
















What exactly does this have to do with asp.net-mvc? And when you say displaying numbers, do you mean in a view?

– user3559349
Nov 12 '18 at 8:41





What exactly does this have to do with asp.net-mvc? And when you say displaying numbers, do you mean in a view?

– user3559349
Nov 12 '18 at 8:41













@StephenMuecke Yes this is related to displaying in view and my project is an asp.net mvc application hence i have tagged this question with mvc tag

– Learning-Overthinker-Confused
Nov 12 '18 at 9:50





@StephenMuecke Yes this is related to displaying in view and my project is an asp.net mvc application hence i have tagged this question with mvc tag

– Learning-Overthinker-Confused
Nov 12 '18 at 9:50













When I execute your code the result is 7,453,215.00, not 74,53,215.00 (is that a typo i your question?). And its not clear why you are using .Format("0:n" + 2 + "",...) instead of just .Format("0:n2", ...). And is the culture the only thing you want to change

– user3559349
Nov 12 '18 at 9:55





When I execute your code the result is 7,453,215.00, not 74,53,215.00 (is that a typo i your question?). And its not clear why you are using .Format("0:n" + 2 + "",...) instead of just .Format("0:n2", ...). And is the culture the only thing you want to change

– user3559349
Nov 12 '18 at 9:55













@StephenMuecke I have updated question with correct code and now getting number properly formatted as per US based format but I want to create number formatter at application level so if tomorrow if any body come and say i would like to format number in xyz culture so that i need to change culture at one place only and not all the place where i have used the code mention in my question

– Learning-Overthinker-Confused
Nov 12 '18 at 10:01






@StephenMuecke I have updated question with correct code and now getting number properly formatted as per US based format but I want to create number formatter at application level so if tomorrow if any body come and say i would like to format number in xyz culture so that i need to change culture at one place only and not all the place where i have used the code mention in my question

– Learning-Overthinker-Confused
Nov 12 '18 at 10:01














One option would be to define the culture in your settings file (or in webconfig) (say named myculture) and then instead of new CultureInfo("en-US") you would use new CultureInfo("Properties.Settings.Default.myculture")

– user3559349
Nov 12 '18 at 10:09





One option would be to define the culture in your settings file (or in webconfig) (say named myculture) and then instead of new CultureInfo("en-US") you would use new CultureInfo("Properties.Settings.Default.myculture")

– user3559349
Nov 12 '18 at 10:09












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258332%2fhow-to-create-a-number-formatter-at-application-level-to-format-numbers-based-on%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258332%2fhow-to-create-a-number-formatter-at-application-level-to-format-numbers-based-on%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo