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.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var