How to format a variable as a percentage string in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            double ratio = 0.95;
            string s = string.Format("{0:0.0%}", ratio);

            Console.WriteLine(s);
        }
    }
}


/*
run:
   
95.0%
 
*/

 



answered Aug 20, 2018 by avibootz

Related questions

1 answer 150 views
1 answer 112 views
112 views asked Oct 30, 2022 by avibootz
1 answer 84 views
1 answer 186 views
2 answers 225 views
...