0

Currency format to get ₹ when use String.Format("{0:C}",45) this code.

Can anyone tell why get like this?

enter image description here

Actually, I want $ symbols with the given value.

2

1 Answer 1

2

That code uses the default culture for the current thread - which is probably your system's default culture.

You have options of:

  • Changing the thread's current culture (e.g. with CultureInfo.CurrentCulture)
  • Specifying a culture explicitly in the string.Format call, before the format string

So for example:

using System;
using System.Globalization;

public class Test
{
    static void Main()
    {
        CultureInfo culture = new CultureInfo("en-US");
        var value = string.Format(culture, "{0:C}", 45);
        Console.WriteLine(value);
    }
}
2
  • once culture changes, it works expected things, but how to get $ without set culture in string.format any further setting?
    – saran a
    Dec 9, 2020 at 7:37
  • @sarana: Well yes, as I said in the answer, you can change the current thread's using CultureInfo.CurrentCulture.
    – Jon Skeet
    Dec 9, 2020 at 8:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.