Dollar next to number in ToString formatting

3

When I try to format a value using .ToString("c2") .NET, the currency symbol is stuck with the number. This makes the formatting ugly and wrong to my point of view.

Example:

cdec("1234.56").toString("c2") | Resultando: "R$1.234,56"

I would like it to return: "R $ 1,234.56" (Number separated from the number).

    
asked by anonymous 03.12.2017 / 16:22

3 answers

2

An alternative for you would be to get the currency symbol and concatenate the value using decimal format N2 .

It would look like this:

Decimal value = 1106.20m;
Console.WriteLine($"Current Culture: {CultureInfo.CurrentCulture.Name}");
Console.WriteLine($"Currency Symbol: {NumberFormatInfo.CurrentInfo.CurrencySymbol}");
Console.WriteLine($"Currency Value:  {NumberFormatInfo.CurrentInfo.CurrencySymbol} {value:N2}");
    
03.12.2017 / 16:33
1

You may not like it, but our symbol is like this. If you want to use another you can format it as a regular number ( F or N ) and addition of the currency symbol manually.

You can change the symbol in our culture or create a different culture the way you need .

    
03.12.2017 / 16:33
0

I use {0:C}

double valor;
valor = double.Parse(txtValor.Text);

MessageBox.Show("O valor é " +String.Formart("{0:C}", valor));

It takes the value of TextBox and displays in MessageBox in the value in the real currency

thus getting value inserted 1000 = $ 1,000.00

Below is my script to calculate salary readjustment it is not complete but maybe it will help you enter

        double salario, percentual, aumento, novosal,a5,a10,a15,a20;
        salario = double.Parse(txtSalario.Text);
        a5  = salario * 5 / 100;
        a10 = salario * 10 / 100;
        a15 = salario * 15 / 100;
        a20 = salario * 20 / 100;

        if(salario <= 280)
        {
            novosal = salario + a20;
            percentual = 10*20/100;
            aumento = a20;

            MessageBox.Show("O salário é " +String.Format("{0:C}",salario)+ "\n o percentual de aumento é "+percentual+"\n o valor do aumento foi de" +String.Format("{0:C}",aumento));
        }
        else if (salario > 280 && salario < 700)
        {
            novosal = salario + a15;
            percentual = salario * 15 / 100;
            aumento = a15;

            MessageBox.Show("O salário é " +String.Format("{0:C}",salario) + "\n o percentual de aumento é " + percentual + "\n o valor do aumento foi de" +String.Format("{0:C}", aumento));
        }
        else if (salario > 700 && salario <1500)
        {
            novosal = salario + a10;
            percentual = salario * 10 / 100;
            aumento = a10;

            MessageBox.Show("O salário atual é " +String.Format("{0:C}", salario) + "\n O percentual de aumento foi de " +percentual+ "\n O aumento foi de " + String.Format("{0:C}",aumento) +"\n Salário atualizado é de "+String.Format("{0:C}", novosal));
        }
        else if (salario >= 1500)
        {
            novosal = salario + a5;
            percentual = salario * 5 / 100;
            aumento = a5;

            MessageBox.Show("O salário é " +String.Format("{0:C}", salario) + "\n o percentual de aumento é " + percentual + "\n o valor do aumento foi de" +String.Format("{0:C}", aumento));
        }

I hope to have helped

    
21.11.2018 / 21:46