C# BigInteger Explicit(BigInteger to Decimal)

Description

BigInteger Explicit(BigInteger to Decimal) Defines an explicit conversion of a BigInteger object to a Decimal value.

Syntax

BigInteger.Explicit(BigInteger to Decimal) has the following syntax.


public static explicit operator decimal (
  BigInteger value
)

Parameters

BigInteger.Explicit(BigInteger to Decimal) has the following parameters.

  • value - The value to convert to a Decimal.

Returns

BigInteger.Explicit(BigInteger to Decimal) method returns An object that contains the value of the value parameter.

Example


using System;// ww w  .  j ava 2 s . c om
using System.IO;
using System.Numerics;

public class Example
{
   public static void Main()
   {
        // BigInteger to Decimal conversion.
        BigInteger goodDecimal = 123123123;
        BigInteger badDecimal = (BigInteger) Decimal.MaxValue; 
        badDecimal += BigInteger.One;
        
        Decimal decimalFromBigInteger;
        
        // Successful conversion using cast operator.
        decimalFromBigInteger = (decimal) goodDecimal;
        Console.WriteLine(decimalFromBigInteger);
        
        // Handle conversion that should result in overflow. 
        try
        {
           decimalFromBigInteger = (decimal) badDecimal;
           Console.WriteLine(decimalFromBigInteger);
        }
        catch (OverflowException e)
        {
           Console.WriteLine("Unable to convert {0}:\n   {1}", 
                             badDecimal, e.Message);
        }
    
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex