The example in this article describes the method for C # to implement percent decimal. Share to everyone for your reference. The specific analysis is as follows:
A percent decimal function is needed recently, and the percentage is in string format (you can take or without a percent sign).
If it's a decimal percentage, that's easy, C # has a p in the number format string.
But the percentage turns decimal. I don't know. A simple look at MSDN, no see (Vertigo).
So, there's a direct way to achieve:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<summary>///converts a percentage to a decimal///</summary>///<param name= "perc" > Percent value, either as a pure value or as a representation of the%,///such as: 65|65%& lt;/param>///<returns></returns> public static decimal perctangletodecimal (string perc) {try {string pa tt = @ "/^ (? <num>[d]{1,}) (%?) $/"; Decimal percnum = Decimal.Parse (System.Text.RegularExpressions.Regex.Match (perc, Patt). groups["Num"]. Value); return percnum/(decimal) 100; catch {return 1;}} |
The function is realized, but it feels a bit heterodoxy.
Look forward to interested in the expert Guidance twos ~ ~
I hope this article will help you with the C # program.