Fixed-Point ("F") Format Specifier

Description

The fixed-point ("F") format specifier converts a number to a string of the form "-ddd.ddd..." where each "d" indicates a digit (0-9).

Item Value
Format specifier "F" or "f"
Supported by All numeric types.
Result Integral and decimal digits with optional negative sign.
Precision specifier Number of decimal digits.
Default precision specifier Defined by System.Globalization.NumberFormatInfo.

Example,

Value Format Formatted
1234.567 ("F", en-US) 1234.57
1234 ("F1", en-US) 1234.0
-1234.56 ("F4", en-US)-1234.5600
-1234.56 ("F4", de-DE) -1234,5600

The following NumberFormatInfo properties controls the formatting.

  • NegativeSign
  • NumberDecimalSeparator
  • NumberDecimalDigits

Example


using System;/*w w  w.jav a2  s  .  c  o m*/
using System.Globalization;
class MainClass
{
   static void Main()
   {
        int integerNumber;
        integerNumber = 17843;
        Console.WriteLine(integerNumber.ToString("F", 
                          CultureInfo.InvariantCulture));
        // Displays 17843.00
        
        integerNumber = -29541;
        Console.WriteLine(integerNumber.ToString("F3", 
                          CultureInfo.InvariantCulture));
        // Displays -29541.000 
   }
}

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