Home > Net >  How to add £ and comma to an amount?
How to add £ and comma to an amount?

Time:09-26

I have the following strings

string a = "1000" string b = "£1,000".

I am doing an Assert.Equal to try and compare the two strings but I need to format one of them to be exactly the same as the other.

I have looked at numerous StackOverflow posts and none have exactly what I require.

I have tried the following:

string getAmount = "1000"

string myStrong = String.Format("{0:#,###.##", getAmount)

but it doesn't work, I get "Input string was not in a correct format" Can anyone help?

Thanks

CodePudding user response:

This is what worked for me

//Convert string to double then add currency formatting.                  
amount = getAmount.ToDouble();                          
var expectedAmount = "£"   string.Format("{0:#,###.00}", Convert.ToDecimal(amount));
  • Related