MiguelM
MiguelM

Reputation: 197

Format a decimal using at least 2 places and at most 6 places

To meet a specification I need to format a decimal value with the rule:

Example:

Value        Formatted
1            1.00
1.1          1.10
1.1234       1.1234
1.123456     1.123456
1.12345678   1.123456

I guess I'll end using a condition, but I wonder if there is a format string which can do this.

Upvotes: 9

Views: 2942

Answers (1)

Barry Kaye
Barry Kaye

Reputation: 7761

Have you tried:

.ToString("0.00####");

Upvotes: 18

Related Questions