C# Convert ToSingle(Double)

Description

Convert ToSingle(Double) converts the value of the specified double-precision floating-point number to an equivalent single-precision floating-point number.

Syntax

Convert.ToSingle(Double) has the following syntax.


public static float ToSingle(
  double value
)

Parameters

Convert.ToSingle(Double) has the following parameters.

  • value - The double-precision floating-point number to convert.

Returns

Convert.ToSingle(Double) method returns A single-precision floating-point number that is equivalent to value. value is rounded using rounding to nearest. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36.

Example


//w  w  w . j a va 2 s  . co  m
using System;
public class MainClass{
  public static void Main(String[] argv){  
    Console.WriteLine(Convert.ToSingle(123.123D));
  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version