RShome
RShome

Reputation: 537

How to add £ and comma to an amount?

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

Upvotes: 0

Views: 170

Answers (1)

RShome
RShome

Reputation: 537

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));

Upvotes: -1

Related Questions