Thousands separator in file having an localization error
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#
|
show 3 more comments
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#
1
what is inSystem.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
|
show 3 more comments
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#
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#
c#
asked Nov 19 '18 at 9:00
ThomasThomas
1,12822148
1,12822148
1
what is inSystem.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
|
show 3 more comments
1
what is inSystem.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
|
show 3 more comments
2 Answers
2
active
oldest
votes
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
orDouble.ToString
methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or theInvariantCulture
) 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 .NETStreamWriter
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.
add a comment |
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);
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
orDouble.ToString
methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or theInvariantCulture
) 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 .NETStreamWriter
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.
add a comment |
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
orDouble.ToString
methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or theInvariantCulture
) 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 .NETStreamWriter
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.
add a comment |
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
orDouble.ToString
methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or theInvariantCulture
) 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 .NETStreamWriter
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.
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
orDouble.ToString
methods to use a specific culture. Rule of thumb: When formatting/parsing numbers always specify a culture (or theInvariantCulture
) 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 .NETStreamWriter
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.
edited Nov 19 '18 at 12:07
answered Nov 19 '18 at 10:10
taffertaffer
8,18721536
8,18721536
add a comment |
add a comment |
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);
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
add a comment |
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);
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
add a comment |
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);
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);
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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