C# Convert ToDecimal(Single)

Description

Convert ToDecimal(Single) converts the value of the specified single-precision floating-point number to the equivalent decimal number.

Syntax

Convert.ToDecimal(Single) has the following syntax.


public static decimal ToDecimal(
  float value
)

Parameters

Convert.ToDecimal(Single) has the following parameters.

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

Returns

Convert.ToDecimal(Single) method returns A decimal number that is equivalent to value.

Example


/*  w w w  .j  a  va 2s .  co m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    Console.WriteLine(Convert.ToDecimal(1234567500.12F));
    Console.WriteLine(Convert.ToDecimal(1234568500.12F));
    
    Console.WriteLine(Convert.ToDecimal(10.980365F));
    Console.WriteLine(Convert.ToDecimal(10.980355F));

  }
}

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