C# Decimal Decimal(Double)

Description

Decimal Decimal(Double) initializes a new instance of Decimal to the value of the specified double-precision floating-point number.

Syntax

Decimal.Decimal(Double) has the following syntax.


public Decimal(
  double value
)

Parameters

Decimal.Decimal(Double) has the following parameters.

  • value - The value to represent as a Decimal.

Example

The following code example creates several Decimal numbers using the constructor overload that initializes a Decimal structure with a Double value.


//from w  w w .  j  av  a2s  .c  o m
using System;

class DecimalCtorDoDemo {
    public static void Main() {
        try {
            decimal decimalNum = new decimal( 1.23456789E+5 );
            Console.WriteLine( "{0,31}", decimalNum );
        } catch( Exception ex ) {
            Console.WriteLine( ex );
        }
    }
}

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