How to convert percentage string to double in C#

1 Answer

0 votes
using System;
 
class Program
{
    public static double PercentageStringToDouble(string value) {
        return double.Parse(value.Replace("%", "")) / 100;
    }
    static void Main() {
        string str = "12.57%";  

        Console.WriteLine(PercentageStringToDouble(str));
    }
}
 
 
 
 
/*
run:
 
0.1257
 
*/

 



answered Oct 30, 2022 by avibootz

Related questions

1 answer 130 views
1 answer 138 views
1 answer 108 views
1 answer 182 views
2 answers 204 views
204 views asked Dec 23, 2016 by avibootz
...