none
get rid of thousands comma separator RRS feed

  • Question

  • Hi,

    I am using N0 to format my number without decimal places.

    How can I also get rid of the thousands comma separator so 1234 will show as 1234 and not 1,234

    Thanks,

    Jassim

    Sunday, June 7, 2015 11:39 AM

Answers

  • If you don't want thousand separators then don't use N0, use F0.

    Or pick any other format that suits your needs: https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx

    Or use a custom format: https://msdn.microsoft.com/en-us/library/0c899ak8%28v=vs.110%29.aspx

    • Proposed as answer by Blackwood Sunday, June 7, 2015 12:19 PM
    • Marked as answer by Fred BaoModerator Monday, June 15, 2015 9:39 AM
    Sunday, June 7, 2015 12:18 PM
    Moderator
  • The number is formatted according to the current culture. If you want to remove the thousand separator you could use a culture that doesn't use thousand separators:

    decimal d = 1234.00M;
    string s = d.ToString("N0", new System.Globalization.CultureInfo("sv-SE")).Replace(" ", "");

    Or you could just replace the thousand separator with an emtpy string:

    string t = d.ToString("N0").Replace(",", "");

    ...or a bit more culture generic:

    string t = d.ToString("N0").Replace(System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSeparator, "");

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Sunday, June 7, 2015 12:07 PM

All replies

  • The number is formatted according to the current culture. If you want to remove the thousand separator you could use a culture that doesn't use thousand separators:

    decimal d = 1234.00M;
    string s = d.ToString("N0", new System.Globalization.CultureInfo("sv-SE")).Replace(" ", "");

    Or you could just replace the thousand separator with an emtpy string:

    string t = d.ToString("N0").Replace(",", "");

    ...or a bit more culture generic:

    string t = d.ToString("N0").Replace(System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSeparator, "");

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Sunday, June 7, 2015 12:07 PM
  • If you don't want thousand separators then don't use N0, use F0.

    Or pick any other format that suits your needs: https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx

    Or use a custom format: https://msdn.microsoft.com/en-us/library/0c899ak8%28v=vs.110%29.aspx

    • Proposed as answer by Blackwood Sunday, June 7, 2015 12:19 PM
    • Marked as answer by Fred BaoModerator Monday, June 15, 2015 9:39 AM
    Sunday, June 7, 2015 12:18 PM
    Moderator
  • Hi Mike,

    This is probably not the right way to do this, but this is Sergey "geyser" Meshkov. You and I worked together on a project a while back and I was wondering if we could get back in touch. I will take no for an answer. Again sorry if this is unappropriate, but I see no private messaging on these forums.

    Regards,

    Serguei

    Thursday, December 21, 2017 8:36 PM