user4546142
user4546142

Reputation:

strange string format percent c# output

does anybody have an idea why following code outputs 1000% for RebatePercent=10 :

return RebatePercent > 0 ? $"{RebatePercent.ToString("0%")}" : "-";

I didn't find anything to output 10%

thx

Upvotes: 2

Views: 236

Answers (2)

Gilad Green
Gilad Green

Reputation: 37299

If you want to keep the use of string interpolation then you can just:

return RebatePercent > 0 ? $"{RebatePercent.ToString()}%" : "-";

Upvotes: 2

apomene
apomene

Reputation: 14389

you can use as:

RebatePercent > 0 ? String.Format("{0}%", RebatePercent) : "-";

and in C#6:

RebatePercent > 0 ? $"{RebatePercent}%" : "-";

Upvotes: 2

Related Questions