intrigued_66
intrigued_66

Reputation: 17248

String formatting for decimal places and thousands

I would like to represent the number 2.3421 as 2.34 but my current formatting shows it as 02.34

If I had the number 1342.323 I would want to show this as 1,342.32

If I had 0.23 this would be shown as 0.23.

What do I change my format string to achieve this? I have:

"{0:0,0.00}"

Upvotes: 2

Views: 3133

Answers (2)

Andreas Rohde
Andreas Rohde

Reputation: 609

Try this:

{0:#,##0.00}

1342.323 should then be 1,342.32

Upvotes: 3

Oded
Oded

Reputation: 499012

Use # where a number is optional instead of 0:

"{0:#,0.00}"

See Custom Numeric Format Strings on MSDN:

"#" | Digit placeholder

Replaces the pound sign with the corresponding digit if one is present; otherwise, no digit appears in the result string.

Upvotes: 8

Related Questions