Thousands separator in file having an localization error












-1















I'm a bit at a loss during a server migration where I moved my c# program from one server to another, the problem occured that the thousands separator suddenly changed without my doing. My guess is that its a localization error, but I'm not sure what to do about it.



Both servers are equal in terms of languages installed, ... .



Example:
932Â 830,00 is shown on the new server instead of 932.830,00 like on the old



Code:



public void mydo(double difference, string filepath)
{
StringBuilder fileContent = new StringBuilder();
fileContent.AppendLine(" " + String.Format("{0:n}", difference));

using (StreamWriter fileHandler = new StreamWriter(filepath))
{
StringBuilder fileContent2 = new StringBuilder();

fileContent2.AppendLine("<HTML><BODY>");
fileContent2.Append(fileContent.ToString());
fileContent2.AppendLine("</BODY></HTML>");

fileHandler.Write(fileContent2.ToString());
}
}









share|improve this question


















  • 1





    what is in System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator property?

    – vasily.sib
    Nov 19 '18 at 9:04











  • java.com/en/download/help/locale.xml

    – Mitch Wheat
    Nov 19 '18 at 9:04











  • @ Patrick Hofman: it's irrelevant in the article. It talsk about windows, not java per se.

    – Mitch Wheat
    Nov 19 '18 at 9:08













  • A little explanation with the link would be useful then.

    – Patrick Hofman
    Nov 19 '18 at 9:08








  • 1





    @ Patrick Hofman: I assumed someone would be able to click on the link and read it.......I can't spoon feed everyone.

    – Mitch Wheat
    Nov 19 '18 at 9:08


















-1















I'm a bit at a loss during a server migration where I moved my c# program from one server to another, the problem occured that the thousands separator suddenly changed without my doing. My guess is that its a localization error, but I'm not sure what to do about it.



Both servers are equal in terms of languages installed, ... .



Example:
932Â 830,00 is shown on the new server instead of 932.830,00 like on the old



Code:



public void mydo(double difference, string filepath)
{
StringBuilder fileContent = new StringBuilder();
fileContent.AppendLine(" " + String.Format("{0:n}", difference));

using (StreamWriter fileHandler = new StreamWriter(filepath))
{
StringBuilder fileContent2 = new StringBuilder();

fileContent2.AppendLine("<HTML><BODY>");
fileContent2.Append(fileContent.ToString());
fileContent2.AppendLine("</BODY></HTML>");

fileHandler.Write(fileContent2.ToString());
}
}









share|improve this question


















  • 1





    what is in System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator property?

    – vasily.sib
    Nov 19 '18 at 9:04











  • java.com/en/download/help/locale.xml

    – Mitch Wheat
    Nov 19 '18 at 9:04











  • @ Patrick Hofman: it's irrelevant in the article. It talsk about windows, not java per se.

    – Mitch Wheat
    Nov 19 '18 at 9:08













  • A little explanation with the link would be useful then.

    – Patrick Hofman
    Nov 19 '18 at 9:08








  • 1





    @ Patrick Hofman: I assumed someone would be able to click on the link and read it.......I can't spoon feed everyone.

    – Mitch Wheat
    Nov 19 '18 at 9:08
















-1












-1








-1








I'm a bit at a loss during a server migration where I moved my c# program from one server to another, the problem occured that the thousands separator suddenly changed without my doing. My guess is that its a localization error, but I'm not sure what to do about it.



Both servers are equal in terms of languages installed, ... .



Example:
932Â 830,00 is shown on the new server instead of 932.830,00 like on the old



Code:



public void mydo(double difference, string filepath)
{
StringBuilder fileContent = new StringBuilder();
fileContent.AppendLine(" " + String.Format("{0:n}", difference));

using (StreamWriter fileHandler = new StreamWriter(filepath))
{
StringBuilder fileContent2 = new StringBuilder();

fileContent2.AppendLine("<HTML><BODY>");
fileContent2.Append(fileContent.ToString());
fileContent2.AppendLine("</BODY></HTML>");

fileHandler.Write(fileContent2.ToString());
}
}









share|improve this question














I'm a bit at a loss during a server migration where I moved my c# program from one server to another, the problem occured that the thousands separator suddenly changed without my doing. My guess is that its a localization error, but I'm not sure what to do about it.



Both servers are equal in terms of languages installed, ... .



Example:
932Â 830,00 is shown on the new server instead of 932.830,00 like on the old



Code:



public void mydo(double difference, string filepath)
{
StringBuilder fileContent = new StringBuilder();
fileContent.AppendLine(" " + String.Format("{0:n}", difference));

using (StreamWriter fileHandler = new StreamWriter(filepath))
{
StringBuilder fileContent2 = new StringBuilder();

fileContent2.AppendLine("<HTML><BODY>");
fileContent2.Append(fileContent.ToString());
fileContent2.AppendLine("</BODY></HTML>");

fileHandler.Write(fileContent2.ToString());
}
}






c#






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 9:00









ThomasThomas

1,12822148




1,12822148








  • 1





    what is in System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator property?

    – vasily.sib
    Nov 19 '18 at 9:04











  • java.com/en/download/help/locale.xml

    – Mitch Wheat
    Nov 19 '18 at 9:04











  • @ Patrick Hofman: it's irrelevant in the article. It talsk about windows, not java per se.

    – Mitch Wheat
    Nov 19 '18 at 9:08













  • A little explanation with the link would be useful then.

    – Patrick Hofman
    Nov 19 '18 at 9:08








  • 1





    @ Patrick Hofman: I assumed someone would be able to click on the link and read it.......I can't spoon feed everyone.

    – Mitch Wheat
    Nov 19 '18 at 9:08
















  • 1





    what is in System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator property?

    – vasily.sib
    Nov 19 '18 at 9:04











  • java.com/en/download/help/locale.xml

    – Mitch Wheat
    Nov 19 '18 at 9:04











  • @ Patrick Hofman: it's irrelevant in the article. It talsk about windows, not java per se.

    – Mitch Wheat
    Nov 19 '18 at 9:08













  • A little explanation with the link would be useful then.

    – Patrick Hofman
    Nov 19 '18 at 9:08








  • 1





    @ Patrick Hofman: I assumed someone would be able to click on the link and read it.......I can't spoon feed everyone.

    – Mitch Wheat
    Nov 19 '18 at 9:08










1




1





what is in System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator property?

– vasily.sib
Nov 19 '18 at 9:04





what is in System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator property?

– vasily.sib
Nov 19 '18 at 9:04













java.com/en/download/help/locale.xml

– Mitch Wheat
Nov 19 '18 at 9:04





java.com/en/download/help/locale.xml

– Mitch Wheat
Nov 19 '18 at 9:04













@ Patrick Hofman: it's irrelevant in the article. It talsk about windows, not java per se.

– Mitch Wheat
Nov 19 '18 at 9:08







@ Patrick Hofman: it's irrelevant in the article. It talsk about windows, not java per se.

– Mitch Wheat
Nov 19 '18 at 9:08















A little explanation with the link would be useful then.

– Patrick Hofman
Nov 19 '18 at 9:08







A little explanation with the link would be useful then.

– Patrick Hofman
Nov 19 '18 at 9:08






1




1





@ Patrick Hofman: I assumed someone would be able to click on the link and read it.......I can't spoon feed everyone.

– Mitch Wheat
Nov 19 '18 at 9:08







@ Patrick Hofman: I assumed someone would be able to click on the link and read it.......I can't spoon feed everyone.

– Mitch Wheat
Nov 19 '18 at 9:08














2 Answers
2






active

oldest

votes


















1














It seems there are more problems here at the same time:




  • It seems your local regional settings use non-break space as thousands separator and comma as decimal symbol. You should specify a culture in the String.Format or Double.ToString methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or the InvariantCulture) because the default culture comes from the the current regional settings, which can be different everywhere.

  • The "Â " sequence is a typical sign that an UTF8 text is rendered with ISO-8859-1 or CP1250 (Latin1 8-bit) codepage. So maybe the dumped text is UTF8 (which is the default encoding of the .NET StreamWriter class), whereas if you don't specify the encoding of a HTML4 output it defaults to ISO-8859-1.

  • And actually you want to use the dot as thousands separator and comma as decimal sign.


Explicitly using a culture (eg. German) can solve your problem with the number formatting:



var culture = CultureInfo.GetCultureInfo("de-DE");
fileContent.Append(difference.ToString(culture));


But if the web page contains diacritical letters or other non-ASCII symbols the encoding issue will appear at other places. Make sure you configure both the StreamWriter and the output HTML content to use the same encoding.






share|improve this answer

































    0














    You can either set your system's locale back to en-US as this says that results in the desired numeric format, which I can't help with because I don't know about your server configuration. Or, you can bypass your system locale with



    String.Format(new CultureInfo("en-US"), "{0:n}", difference);





    share|improve this answer
























    • setting the culture info works. In my case I set it for the thread as a whole then after your answer: Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); what I'm confused about though is why it is a problem. As both servers (aside from the old being 2008 and the new one 2016) are identical.

      – Thomas
      Nov 19 '18 at 10:09











    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%2f53371228%2fthousands-separator-in-file-having-an-localization-error%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    It seems there are more problems here at the same time:




    • It seems your local regional settings use non-break space as thousands separator and comma as decimal symbol. You should specify a culture in the String.Format or Double.ToString methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or the InvariantCulture) because the default culture comes from the the current regional settings, which can be different everywhere.

    • The "Â " sequence is a typical sign that an UTF8 text is rendered with ISO-8859-1 or CP1250 (Latin1 8-bit) codepage. So maybe the dumped text is UTF8 (which is the default encoding of the .NET StreamWriter class), whereas if you don't specify the encoding of a HTML4 output it defaults to ISO-8859-1.

    • And actually you want to use the dot as thousands separator and comma as decimal sign.


    Explicitly using a culture (eg. German) can solve your problem with the number formatting:



    var culture = CultureInfo.GetCultureInfo("de-DE");
    fileContent.Append(difference.ToString(culture));


    But if the web page contains diacritical letters or other non-ASCII symbols the encoding issue will appear at other places. Make sure you configure both the StreamWriter and the output HTML content to use the same encoding.






    share|improve this answer






























      1














      It seems there are more problems here at the same time:




      • It seems your local regional settings use non-break space as thousands separator and comma as decimal symbol. You should specify a culture in the String.Format or Double.ToString methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or the InvariantCulture) because the default culture comes from the the current regional settings, which can be different everywhere.

      • The "Â " sequence is a typical sign that an UTF8 text is rendered with ISO-8859-1 or CP1250 (Latin1 8-bit) codepage. So maybe the dumped text is UTF8 (which is the default encoding of the .NET StreamWriter class), whereas if you don't specify the encoding of a HTML4 output it defaults to ISO-8859-1.

      • And actually you want to use the dot as thousands separator and comma as decimal sign.


      Explicitly using a culture (eg. German) can solve your problem with the number formatting:



      var culture = CultureInfo.GetCultureInfo("de-DE");
      fileContent.Append(difference.ToString(culture));


      But if the web page contains diacritical letters or other non-ASCII symbols the encoding issue will appear at other places. Make sure you configure both the StreamWriter and the output HTML content to use the same encoding.






      share|improve this answer




























        1












        1








        1







        It seems there are more problems here at the same time:




        • It seems your local regional settings use non-break space as thousands separator and comma as decimal symbol. You should specify a culture in the String.Format or Double.ToString methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or the InvariantCulture) because the default culture comes from the the current regional settings, which can be different everywhere.

        • The "Â " sequence is a typical sign that an UTF8 text is rendered with ISO-8859-1 or CP1250 (Latin1 8-bit) codepage. So maybe the dumped text is UTF8 (which is the default encoding of the .NET StreamWriter class), whereas if you don't specify the encoding of a HTML4 output it defaults to ISO-8859-1.

        • And actually you want to use the dot as thousands separator and comma as decimal sign.


        Explicitly using a culture (eg. German) can solve your problem with the number formatting:



        var culture = CultureInfo.GetCultureInfo("de-DE");
        fileContent.Append(difference.ToString(culture));


        But if the web page contains diacritical letters or other non-ASCII symbols the encoding issue will appear at other places. Make sure you configure both the StreamWriter and the output HTML content to use the same encoding.






        share|improve this answer















        It seems there are more problems here at the same time:




        • It seems your local regional settings use non-break space as thousands separator and comma as decimal symbol. You should specify a culture in the String.Format or Double.ToString methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or the InvariantCulture) because the default culture comes from the the current regional settings, which can be different everywhere.

        • The "Â " sequence is a typical sign that an UTF8 text is rendered with ISO-8859-1 or CP1250 (Latin1 8-bit) codepage. So maybe the dumped text is UTF8 (which is the default encoding of the .NET StreamWriter class), whereas if you don't specify the encoding of a HTML4 output it defaults to ISO-8859-1.

        • And actually you want to use the dot as thousands separator and comma as decimal sign.


        Explicitly using a culture (eg. German) can solve your problem with the number formatting:



        var culture = CultureInfo.GetCultureInfo("de-DE");
        fileContent.Append(difference.ToString(culture));


        But if the web page contains diacritical letters or other non-ASCII symbols the encoding issue will appear at other places. Make sure you configure both the StreamWriter and the output HTML content to use the same encoding.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 19 '18 at 12:07

























        answered Nov 19 '18 at 10:10









        taffertaffer

        8,18721536




        8,18721536

























            0














            You can either set your system's locale back to en-US as this says that results in the desired numeric format, which I can't help with because I don't know about your server configuration. Or, you can bypass your system locale with



            String.Format(new CultureInfo("en-US"), "{0:n}", difference);





            share|improve this answer
























            • setting the culture info works. In my case I set it for the thread as a whole then after your answer: Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); what I'm confused about though is why it is a problem. As both servers (aside from the old being 2008 and the new one 2016) are identical.

              – Thomas
              Nov 19 '18 at 10:09
















            0














            You can either set your system's locale back to en-US as this says that results in the desired numeric format, which I can't help with because I don't know about your server configuration. Or, you can bypass your system locale with



            String.Format(new CultureInfo("en-US"), "{0:n}", difference);





            share|improve this answer
























            • setting the culture info works. In my case I set it for the thread as a whole then after your answer: Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); what I'm confused about though is why it is a problem. As both servers (aside from the old being 2008 and the new one 2016) are identical.

              – Thomas
              Nov 19 '18 at 10:09














            0












            0








            0







            You can either set your system's locale back to en-US as this says that results in the desired numeric format, which I can't help with because I don't know about your server configuration. Or, you can bypass your system locale with



            String.Format(new CultureInfo("en-US"), "{0:n}", difference);





            share|improve this answer













            You can either set your system's locale back to en-US as this says that results in the desired numeric format, which I can't help with because I don't know about your server configuration. Or, you can bypass your system locale with



            String.Format(new CultureInfo("en-US"), "{0:n}", difference);






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 19 '18 at 9:12









            KilvesKilves

            17215




            17215













            • setting the culture info works. In my case I set it for the thread as a whole then after your answer: Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); what I'm confused about though is why it is a problem. As both servers (aside from the old being 2008 and the new one 2016) are identical.

              – Thomas
              Nov 19 '18 at 10:09



















            • setting the culture info works. In my case I set it for the thread as a whole then after your answer: Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); what I'm confused about though is why it is a problem. As both servers (aside from the old being 2008 and the new one 2016) are identical.

              – Thomas
              Nov 19 '18 at 10:09

















            setting the culture info works. In my case I set it for the thread as a whole then after your answer: Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); what I'm confused about though is why it is a problem. As both servers (aside from the old being 2008 and the new one 2016) are identical.

            – Thomas
            Nov 19 '18 at 10:09





            setting the culture info works. In my case I set it for the thread as a whole then after your answer: Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); what I'm confused about though is why it is a problem. As both servers (aside from the old being 2008 and the new one 2016) are identical.

            – Thomas
            Nov 19 '18 at 10:09


















            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%2f53371228%2fthousands-separator-in-file-having-an-localization-error%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

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)