How does convert.ToString (C0) work?

I have different scripts. I need an output where the value should return comma separated values ​​in the ₹ format it does on my system where I have the rupee ₹ character. If, on a custom system, C0 returns a $ with comma separated values, I don't know if it has a ₹ character on its system or not. Can someone advise.

PS. I am using an expression in the subject line where I cannot use more functions. I used convert.ToString ("C0").

+3


source to share


2 answers


You can brute force search a string for any currency symbols and change them to any symbol you want, for example:



string s = "$";
foreach (var c in s)
{
    var category = CharUnicodeInfo.GetUnicodeCategory(c);

    if (category == UnicodeCategory.CurrencySymbol)
    {
        //Force convert the char to what every character you want
    }
}

      

+1


source


You can always set the current UI culture in your application and then use it when you need to output the correct currency symbol. For example:

double amount = 101.12;
Thread.CurrentThread.CurrentUICulture = new CultureInfo("hi-IN");
Console.WriteLine(amount.ToString("C0", Thread.CurrentThread.CurrentUICulture));

      

If the issue is related to the question of whether a culture exists on a running computer, this code might help:



bool cultureExists = false;
try
{
    CultureInfo cultureInfo = new CultureInfo("hi-IN");
    cultureExists = true;
}
catch
{
    // nothing here
}

      

If you find it doesn't exist, you will have to create it (if you have enough machine permissions to create a culture). Here's a link that can help with that if you need it: http://www.codeproject.com/Tips/988807/Net-custom-Culture-with-use-case

+1


source







All Articles