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.

Akif
  • 7,098
  • 7
  • 27
  • 53
saran a
  • 21
  • 6

1 Answers1

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);
    }
}
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • once culture changes, it works expected things, but how to get $ without set culture in string.format any further setting? – saran a Dec 09 '20 at 07:37
  • @sarana: Well yes, as I said in the answer, you can change the current thread's using `CultureInfo.CurrentCulture`. – Jon Skeet Dec 09 '20 at 08:21