CareTaker22
CareTaker22

Reputation: 1300

Using a comma in a 'double' with Math Round

I would like to display my calculated amount with a , and the last two decimal places ex. 1000.00 = 1,000.00. I have tried the coding below, and it works, but It removes my two decimal places when I round it at the end.

lblTotalInclVatAmount.Content = "R " + Math.Round((double + double),2).ToString("N0");

It's sounds simple enough. Any advice would be appreciated, thank you! :)

Upvotes: 2

Views: 1669

Answers (2)

Bolu
Bolu

Reputation: 8786

The precision specifier indicates the desired number of digits after the decimal point.

As such you are looking for ToString("N2") instead.

You can see more information from: The Numeric ("N") Format Specifier.

Upvotes: 1

Mick3y
Mick3y

Reputation: 46

double d = 1000;
string s = d.ToString("N");

s is now 1,000.00

Upvotes: 1

Related Questions