C # To implement percent decimal method

Source: Internet
Author: User
Tags string format

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.