Reputation: 2799
I have a technical problem with using percentage in StringFormat
method.
The result of String.Format("{0:P}", 0.8526)
is 85.26%
but I think it should be 0.8526%
Is it correct ? If yes , How can I get 0.8526%
?
Upvotes: 16
Views: 44244
Reputation: 15357
A percentage is considered from 0-100% and the related floating pointer number from 0.0-1.0 as it is a ratio between two numbers.
Upvotes: 2
Reputation: 2758
String.Format
will multiply by 100 when you use % or :p String.Format
You should divide by 100 first if you want to get what you are looking for.
Upvotes: 2
Reputation: 33809
Yes mathematically 0.8526 is equal to 85.26%. If you need to get 0.8526% then try this
String.Format("{0:P}", 0.8526/100)
Upvotes: 17