Format double value in percentage with percent ("P") format in CSharp
Description
The following code shows how to format double value in percentage with percent ("P") format.
Example
using System;/*from w ww.j a va 2 s . co m*/
using System.Globalization;
public class MainClass {
static void Main()
{
double number = .2468013;
Console.WriteLine(number.ToString("P", CultureInfo.InvariantCulture));
// Displays 24.68 %
Console.WriteLine(number.ToString("P",
CultureInfo.CreateSpecificCulture("hr-HR")));
// Displays 24,68%
Console.WriteLine(number.ToString("P1", CultureInfo.InvariantCulture));
// Displays 24.7 %
}
}
The code above generates the following result.