DECIMALとは? わかりやすく解説

decimal

別表記:デシマル

「decimal」の意味

「decimal」は、10進法に関連することを意味する英単語である。10進法は、数学や計算で一般的に使用される基数システムであり、0から9までの10種類の数字を用いる。例えば、10進法における小数点以下の数値は、decimal point(小数点)と呼ばれる。

「decimal」の発音・読み方

「decimal」の発音は、IPA表記では /ˈdɛsɪməl/ であり、IPAのカタカナ読みでは「デシマル」となる。日本人が発音するカタカナ英語では「デシマル」と読む。

「decimal」の定義を英語で解説

英語での「decimal」の定義は、「relating to or denoting a system of numbers and arithmetic based on the number ten, tenth parts, and powers of ten」となる。これは、「10、10分の1、10のべき乗に基づく数と算術に関連するまたはそれを示す」という意味である。

「decimal」の類語

「decimal」の類語には、以下のようなものがある。

Base-10

Base-10は、10を基数とする数学的なシステムを指す。10進法と同義である。

Denary

Denaryは、10進法を意味する古い英語の言葉である。現代ではあまり使われないが、歴史的な文献などで見られることがある。

「decimal」に関連する用語・表現

Decimal point

Decimal pointは、小数点のことを指す。10進法において、整数部と小数部を区切る記号である。

Decimal fraction

Decimal fractionは、10進法における分数のことである。例えば、0.25は、10進法で表された四分の一を意味する。

「decimal」の例文

1. The decimal system is widely used in mathematics and everyday life.(日本語訳:10進法は、数学や日常生活で広く使われている。) 2. The number 0.5 represents a decimal fraction.(日本語訳:0.5は、10進法で表された分数を表している。) 3. In the decimal system, the value of each digit depends on its position.(日本語訳:10進法では、各桁の値はその位置によって決まる。) 4. The decimal point separates the integer part from the fractional part.(日本語訳:小数点は、整数部と小数部を区切る。) 5. Decimal notation is a convenient way to represent numbers with fractions.(日本語訳:10進表記は、分数を含む数を表す便利な方法である。) 6. The decimal system is also known as the base-10 system.(日本語訳:10進法は、基数10のシステムとしても知られている。) 7. The decimal equivalent of the fraction 1/4 is 0.25.(日本語訳:分数1/4の10進法による等価値は0.25である。) 8. The decimal place value system is easy to understand and use.(日本語訳:10進法の位取り記数法は理解しやすく、使いやすい。) 9. The number 3.14159 is a decimal approximation of pi.(日本語訳:3.14159は、円周率πの10進法による近似値である。) 10. Computers use binary, not decimal, to process information.(日本語訳:コンピュータは、情報処理に10進法ではなく、2進法を使用する。)

デシマル【decimal】

読み方:でしまる

小数。小数位。また、十進法。「―ポイント(=小数点)」


Decimal コンストラクタ (UInt64)

Decimal の新しいインスタンスを作成して、その値を、指定した 64 ビット符号なし整数に設定します。

このコンストラクタは、CLS に準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Sub New ( _
    value As ULong _
)
[CLSCompliantAttribute(false)] 
public Decimal (
    ulong value
)
[CLSCompliantAttribute(false)] 
public:
Decimal (
    usigned long long value
)
/** @attribute CLSCompliantAttribute(false) */ 
public Decimal (
    UInt64 value
)
CLSCompliantAttribute(false) 
public function Decimal (
    value : ulong
)

パラメータ

value

Decimal として表す値。

使用例使用例

Decimal 構造体を UInt64 値で初期化するコンストラクタのオーバーロードを使用して、複数の Decimal 数値を作成するコード例を次に示します。

' Example of the Decimal( UInt64 ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module DecimalCtorULDemo

    ' Create a Decimal object and display its value.
    Sub CreateDecimal( value As UInt64, valToStr
 As String )

        Dim decimalNum As New
 Decimal( value )

        ' Format the constructor for display.
        Dim ctor As String
 = _
            String.Format( "Decimal( {0} )",
 valToStr )

        ' Display the constructor and its value.
        Console.WriteLine( "{0,-33}{1,22}", ctor,
 decimalNum )
    End Sub
    
    Sub Main( )

        Console.WriteLine( _
            "This example of the Decimal( UInt64 ) constructor
 " & _
            vbCrLf & "generates the following output."
 & vbCrLf )
        Console.WriteLine( "{0,-33}{1,22}", "Constructor",
 "Value" )
        Console.WriteLine( "{0,-33}{1,22}", "-----------",
 "-----" )

        ' Construct Decimal objects from UInt64 values.
        ' UInt64.MinValue and UInt64.MaxValue are not defined in VB.
        CreateDecimal( Convert.ToUInt64( 0 ), """UInt64.MinValue"""
 )
        CreateDecimal( Convert.ToUInt64( 18446744073709551615D ), _
            """UInt64.MaxValue"""
 )
        CreateDecimal( Convert.ToUInt64( Long.MaxValue ), _
            "Long.MaxValue" )              
        CreateDecimal( Convert.ToUInt64( 999999999999999999 ), _
            "999999999999999999" )               
 
        CreateDecimal( Convert.ToUInt64( &H2000000000000000 ), _
            "&H2000000000000000" )           
     
        CreateDecimal( Convert.ToUInt64( 16140901064495857664.0 ), _
            "16140901064495857664.0" )           
     
    End Sub 
End Module 

' This example of the Decimal( UInt64 ) constructor
' generates the following output.
' 
' Constructor                                       Value
' -----------                                       -----
' Decimal( "UInt64.MinValue" )                          0
' Decimal( "UInt64.MaxValue" )       18446744073709551615
' Decimal( Long.MaxValue )            9223372036854775807
' Decimal( 999999999999999999 )        999999999999999999
' Decimal( &H2000000000000000 )       2305843009213693952
' Decimal( 16140901064495857664.0 )  16140901064495857664
// Example of the decimal( ulong ) constructor.
using System;

class DecimalCtorLDemo
{
    // Create a decimal object and display its value.
    public static void CreateDecimal(
 ulong value, string valToStr )
    {
        decimal decimalNum = new decimal( value );

        // Format the constructor for display.
        string ctor = String.Format( "decimal( {0} )",
 valToStr );

        // Display the constructor and its value.
        Console.WriteLine( "{0,-35}{1,22}", ctor, decimalNum );
    }
    
    public static void Main(
 )
    {
        Console.WriteLine( "This example of the decimal( ulong ) " +
            "constructor \ngenerates the following output.\n" );
        Console.WriteLine( "{0,-35}{1,22}", "Constructor", "Value"
 );
        Console.WriteLine( "{0,-35}{1,22}", "-----------", "-----"
 );

        // Construct decimal objects from ulong values.
        CreateDecimal( ulong.MinValue, "ulong.MinValue" );
        CreateDecimal( ulong.MaxValue, "ulong.MaxValue" );
        CreateDecimal( long.MaxValue, "long.MaxValue" );
        CreateDecimal( 999999999999999999, "999999999999999999" );
        CreateDecimal( 0x2000000000000000, "0x2000000000000000" );
        CreateDecimal( 0xE000000000000000, "0xE000000000000000" );
    }
}

/*
This example of the decimal( ulong ) constructor
generates the following output.

Constructor                                         Value
-----------                                         -----
decimal( ulong.MinValue )                               0
decimal( ulong.MaxValue )            18446744073709551615
decimal( long.MaxValue )              9223372036854775807
decimal( 999999999999999999 )          999999999999999999
decimal( 0x2000000000000000 )         2305843009213693952
decimal( 0xE000000000000000 )        16140901064495857664
*/
// Example of the Decimal( unsigned __int64 ) constructor.
using namespace System;

// Create a Decimal object and display its value.
void CreateDecimal( unsigned __int64 value, String^ valToStr )
{
   Decimal decimalNum = Decimal(value);
   
   // Format the constructor for display.
   String^ ctor = String::Format( "Decimal( {0} )", valToStr );
   
   // Display the constructor and its value.
   Console::WriteLine( "{0,-33}{1,22}", ctor, decimalNum );
}

int main()
{
   Console::WriteLine( "This example of the Decimal( unsigned "
   "__int64 ) constructor \ngenerates the following output.\n" );
   Console::WriteLine( "{0,-33}{1,22}", "Constructor", "Value"
 );
   Console::WriteLine( "{0,-33}{1,22}", "-----------", "-----"
 );
   
   // Construct Decimal objects from unsigned __int64 values.
   CreateDecimal( UInt64::MinValue, "UInt64::MinValue" );
   CreateDecimal( UInt64::MaxValue, "UInt64::MaxValue" );
   CreateDecimal( Int64::MaxValue, "Int64::MaxValue" );
   CreateDecimal( 999999999999999999, "999999999999999999" );
   CreateDecimal( 0x2000000000000000, "0x2000000000000000" );
   CreateDecimal( 0xE000000000000000, "0xE000000000000000" );
}

/*
This example of the Decimal( unsigned __int64 ) constructor
generates the following output.

Constructor                                       Value
-----------                                       -----
Decimal( UInt64::MinValue )                           0
Decimal( UInt64::MaxValue )        18446744073709551615
Decimal( Int64::MaxValue )          9223372036854775807
Decimal( 999999999999999999 )        999999999999999999
Decimal( 0x2000000000000000 )       2305843009213693952
Decimal( 0xE000000000000000 )      16140901064495857664
*/
// Example of the decimal( ulong ) constructor.
import System.* ;

class DecimalCtorLDemo
{   
    // Create a decimal object and display its value.
    public static void CreateDecimal(UInt64
 value, String valToStr)
    {
        
        System.Decimal decimalNum =  new System.Decimal(value);
        
        // Format the constructor for display.
        String ctor = String.Format("decimal( {0} )", valToStr);
        
        // Display the constructor and its value.
        Console.WriteLine("{0,-35}{1,22}", ctor, decimalNum);
    } //CreateDecimal

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of the decimal( ulong ) " 
            + "constructor \ngenerates the following output.\n"));
        Console.WriteLine("{0,-35}{1,22}", "Constructor", "Value");
        Console.WriteLine("{0,-35}{1,22}", "-----------", "-----");
        
        // Construct decimal objects from ulong values.
        //CreateDecimal(Long.MIN_VALUE, "ulong.MinValue");
        CreateDecimal(UInt64.MinValue, "ulong.MinValue");
        CreateDecimal(UInt64.MaxValue, "ulong.MaxValue");
        
        CreateDecimal(System.Convert.ToUInt64(Long.MAX_VALUE), "long.MaxValue");
        CreateDecimal(System.Convert.ToUInt64(999999999999999999L), 
            "999999999999999999" );
        CreateDecimal(System.Convert.ToUInt64(0x2000000000000000L), 
            "0x2000000000000000" );
        CreateDecimal((UInt64) 0xE000000000000000L, "0xE000000000000000"
 );
    } //main
} //DecimalCtorLDemo

/*
This example of the decimal( ulong ) constructor
generates the following output.

Constructor                                         Value
-----------                                         -----
decimal( ulong.MinValue )                               0
decimal( ulong.MaxValue )            18446744073709551615
decimal( long.MaxValue )              9223372036854775807
decimal( 999999999999999999 )          999999999999999999
decimal( 0x2000000000000000 )         2305843009213693952
decimal( 0xE000000000000000 )        16140901064495857664
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Decimal コンストラクタ (Double)

Decimal の新しいインスタンスを作成し、その値を、指定した倍精度浮動小数点数に設定します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

public Decimal (
    double value
)
public:
Decimal (
    double value
)
public Decimal (
    double value
)

パラメータ

value

Decimal として表す値。

例外例外
例外の種類条件

OverflowException

value が MaxValue より大きい値か、MinValue より小さい値です。

または

value が Double.NaN、Double.PositiveInfinity、または Double.NegativeInfinity です。

解説解説
使用例使用例

Decimal 構造体を Double 値で初期化するコンストラクタのオーバーロードを使用して、複数の Decimal 数値を作成するコード例を次に示します。

' Example of the Decimal( Double ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module DecimalCtorDoDemo

    ' Get the exception type name; remove the namespace prefix.
    Function GetExceptionType( ex As Exception
 ) As String

        Dim exceptionType   As String
 = ex.GetType( ).ToString( )
        Return exceptionType.Substring( _
            exceptionType.LastIndexOf( "."c ) + 1
 )
    End Function

    ' Create a Decimal object and display its value.
    Sub CreateDecimal( value As Double,
 valToStr As String )

        ' Format and display the constructor.
        Console.Write( "{0,-34}", _
            String.Format( "Decimal( {0} )",
 valToStr ) )

        ' Construct the Decimal value.
        Try
            Dim decimalNum As New
 Decimal( value )

            ' Display the value if it was created successfully.
            Console.WriteLine( "{0,31}", decimalNum
 )

        ' Display the exception type if an exception was thrown.
        Catch ex As Exception
            Console.WriteLine( "{0,31}", GetExceptionType(
 ex ) )
        End Try
    End Sub
    
    Sub Main( )

        Console.WriteLine( _
            "This example of the Decimal( Double ) constructor
 " & _
            vbCrLf & "generates the following output."
 & vbCrLf )
        Console.WriteLine( "{0,-34}{1,31}", "Constructor",
 _
            "Value or Exception" )
        Console.WriteLine( "{0,-34}{1,31}", "-----------",
 _
            "------------------" )

        ' Construct Decimal objects from Double values.
        CreateDecimal( 1.23456789E+5, "1.23456789E+5"
 )                
        CreateDecimal( 1.234567890123E+15, "1.234567890123E+15"
 )                
        CreateDecimal( 1.2345678901234567E+25, _
            "1.2345678901234567E+25" )
        CreateDecimal( 1.2345678901234567E+35, _
            "1.2345678901234567E+35" )
        CreateDecimal( 1.23456789E-5, "1.23456789E-5"
 )                
        CreateDecimal( 1.234567890123E-15, "1.234567890123E-15"
 )      
        CreateDecimal( 1.2345678901234567E-25, _
            "1.2345678901234567E-25" ) 
        CreateDecimal( 1.2345678901234567E-35, _
            "1.2345678901234567E-35" ) 
        CreateDecimal( 1.0 / 7.0, "1.0 / 7.0" ) 
    End Sub 
End Module 

' This example of the Decimal( Double ) constructor
' generates the following output.
' 
' Constructor                                    Value or Exception
' -----------                                    ------------------
' Decimal( 1.23456789E+5 )                               123456.789
' Decimal( 1.234567890123E+15 )                    1234567890123000
' Decimal( 1.2345678901234567E+25 )      12345678901234600000000000
' Decimal( 1.2345678901234567E+35 )               OverflowException
' Decimal( 1.23456789E-5 )                          0.0000123456789
' Decimal( 1.234567890123E-15 )       0.000000000000001234567890123
' Decimal( 1.2345678901234567E-25 )  0.0000000000000000000000001235
' Decimal( 1.2345678901234567E-35 )                               0
' Decimal( 1.0 / 7.0 )                            0.142857142857143
// Example of the decimal( double ) constructor.
using System;

class DecimalCtorDoDemo
{
    // Get the exception type name; remove the namespace prefix.
    public static string
 GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring( 
            exceptionType.LastIndexOf( '.' )+1 );
    }

    // Create a decimal object and display its value.
    public static void CreateDecimal(
 double value, string valToStr )
    {
        // Format and display the constructor.
        Console.Write( "{0,-34}", 
            String.Format( "decimal( {0} )", valToStr ) );

        try
        {
            // Construct the decimal value.
            decimal decimalNum = new decimal( value );

            // Display the value if it was created successfully.
            Console.WriteLine( "{0,31}", decimalNum );
        }
        catch( Exception ex )
        {
            // Display the exception type if an exception was thrown.
            Console.WriteLine( "{0,31}", GetExceptionType( ex ) );
        }
    }
    
    public static void Main(
 )
    {
        Console.WriteLine( "This example of the decimal( double ) " +
            "constructor \ngenerates the following output.\n" );
        Console.WriteLine( "{0,-34}{1,31}", "Constructor", 
            "Value or Exception" );
        Console.WriteLine( "{0,-34}{1,31}", "-----------", 
            "------------------" );

        // Construct decimal objects from double values.
        CreateDecimal( 1.23456789E+5, "1.23456789E+5" );
        CreateDecimal( 1.234567890123E+15, "1.234567890123E+15" );
        CreateDecimal( 1.2345678901234567E+25, 
            "1.2345678901234567E+25" );
        CreateDecimal( 1.2345678901234567E+35, 
            "1.2345678901234567E+35" );
        CreateDecimal( 1.23456789E-5, "1.23456789E-5" );
        CreateDecimal( 1.234567890123E-15, "1.234567890123E-15" );
        CreateDecimal( 1.2345678901234567E-25, 
            "1.2345678901234567E-25" );
        CreateDecimal( 1.2345678901234567E-35, 
            "1.2345678901234567E-35" );
        CreateDecimal( 1.0 / 7.0, "1.0 / 7.0" );
    }
}

/*
This example of the decimal( double ) constructor
generates the following output.

Constructor                                    Value or Exception
-----------                                    ------------------
decimal( 1.23456789E+5 )                               123456.789
decimal( 1.234567890123E+15 )                    1234567890123000
decimal( 1.2345678901234567E+25 )      12345678901234600000000000
decimal( 1.2345678901234567E+35 )               OverflowException
decimal( 1.23456789E-5 )                          0.0000123456789
decimal( 1.234567890123E-15 )       0.000000000000001234567890123
decimal( 1.2345678901234567E-25 )  0.0000000000000000000000001235
decimal( 1.2345678901234567E-35 )                               0
decimal( 1.0 / 7.0 )                            0.142857142857143
*/
// Example of the Decimal( double ) constructor.
using namespace System;

// Get the exception type name; remove the namespace prefix.
String^ GetExceptionType( Exception^ ex )
{
   String^ exceptionType = ex->GetType()->ToString();
   return exceptionType->Substring( exceptionType->LastIndexOf(
 '.' ) + 1 );
}


// Create a Decimal object and display its value.
void CreateDecimal( double value, String^ valToStr )
{
   
   // Format and display the constructor.
   Console::Write( "{0,-34}", String::Format( "Decimal( {0} )",
 valToStr ) );
   try
   {
      
      // Construct the Decimal value.
      Decimal decimalNum = Decimal(value);
      
      // Display the value if it was created successfully.
      Console::WriteLine( "{0,31}", decimalNum );
   }
   catch ( Exception^ ex ) 
   {
      
      // Display the exception type if an exception was thrown.
      Console::WriteLine( "{0,31}", GetExceptionType( ex ) );
   }

}

int main()
{
   Console::WriteLine( "This example of the Decimal( double ) "
   "constructor \ngenerates the following output.\n" );
   Console::WriteLine( "{0,-34}{1,31}", "Constructor", "Value
 or Exception" );
   Console::WriteLine( "{0,-34}{1,31}", "-----------", "------------------"
 );
   
   // Construct Decimal objects from double values.
   CreateDecimal( 1.23456789E+5, "1.23456789E+5" );
   CreateDecimal( 1.234567890123E+15, "1.234567890123E+15" );
   CreateDecimal( 1.2345678901234567E+25, "1.2345678901234567E+25" );
   CreateDecimal( 1.2345678901234567E+35, "1.2345678901234567E+35" );
   CreateDecimal( 1.23456789E-5, "1.23456789E-5" );
   CreateDecimal( 1.234567890123E-15, "1.234567890123E-15" );
   CreateDecimal( 1.2345678901234567E-25, "1.2345678901234567E-25" );
   CreateDecimal( 1.2345678901234567E-35, "1.2345678901234567E-35" );
   CreateDecimal( 1.0 / 7.0, "1.0 / 7.0" );
}

/*
This example of the Decimal( double ) constructor
generates the following output.

Constructor                                    Value or Exception
-----------                                    ------------------
Decimal( 1.23456789E+5 )                               123456.789
Decimal( 1.234567890123E+15 )                    1234567890123000
Decimal( 1.2345678901234567E+25 )      12345678901234600000000000
Decimal( 1.2345678901234567E+35 )               OverflowException
Decimal( 1.23456789E-5 )                          0.0000123456789
Decimal( 1.234567890123E-15 )       0.000000000000001234567890123
Decimal( 1.2345678901234567E-25 )  0.0000000000000000000000001235
Decimal( 1.2345678901234567E-35 )                               0
Decimal( 1.0 / 7.0 )                            0.142857142857143
*/
// Example of the decimal( double ) constructor.
import System.* ;

class DecimalCtorDoDemo
{   
    // Get the exception type name; remove the namespace prefix.
    public static String GetExceptionType(System.Exception
 ex)
    {
        String exceptionType = ex.GetType().ToString();
        return exceptionType.Substring((exceptionType.LastIndexOf('.')
 + 1)) ;
    } //GetExceptionType

    // Create a decimal object and display its value.
    public static void CreateDecimal(double
 value, String valToStr) 
    {
        // Format and display the constructor.
        Console.Write("{0,-34}", String.Format("decimal( {0} )",
 valToStr));
        
        try {
            // Construct the decimal value.
            System.Decimal decimalNum =  new System.Decimal(value);
            
            // Display the value if it was created successfully.
            Console.WriteLine("{0,31}", decimalNum);
        }
        catch(System.Exception  ex) {        
            // Display the exception type if an exception was thrown.
            Console.WriteLine("{0,31}", GetExceptionType(ex));
        }
    } //CreateDecimal

    public static void main(String[]
 args)
    {

        Console.WriteLine(("This example of the decimal( double ) " 
            + "constructor \ngenerates the following output.\n"));
        Console.WriteLine("{0,-34}{1,31}", "Constructor", "Value
 or Exception");
        Console.WriteLine("{0,-34}{1,31}", "-----------", "------------------");
        
        // Construct decimal objects from double values.
        CreateDecimal(123456.789, "1.23456789E+5");
        CreateDecimal(1.234567890123E+15 , "1.234567890123E+15");
        CreateDecimal(1.23456789012346E+25, "1.2345678901234567E+25");
        CreateDecimal(1.23456789012346E+35, "1.2345678901234567E+35");
        CreateDecimal(1.23456789E-05, "1.23456789E-5");
        CreateDecimal(1.234567890123E-15, "1.234567890123E-15");
        CreateDecimal(1.23456789012346E-25, "1.2345678901234567E-25");
        CreateDecimal(1.23456789012346E-35, "1.2345678901234567E-35");
        CreateDecimal(1.0 / 7.0, "1.0 / 7.0");
    } //main
} //DecimalCtorDoDemo

/*
This example of the decimal( double ) constructor
generates the following output.

Constructor                                    Value or Exception
-----------                                    ------------------
decimal( 1.23456789E+5 )                               123456.789
decimal( 1.234567890123E+15 )                    1234567890123000
decimal( 1.2345678901234567E+25 )      12345678901234600000000000
decimal( 1.2345678901234567E+35 )               OverflowException
decimal( 1.23456789E-5 )                          0.0000123456789
decimal( 1.234567890123E-15 )       0.000000000000001234567890123
decimal( 1.2345678901234567E-25 )  0.0000000000000000000000001235
decimal( 1.2345678901234567E-35 )                               0
decimal( 1.0 / 7.0 )                            0.142857142857143
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Decimal コンストラクタ (Single)

Decimal の新しいインスタンスを作成し、その値を、指定した単精度浮動小数点数に設定します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

public Decimal (
    float value
)
public:
Decimal (
    float value
)
public Decimal (
    float value
)

パラメータ

value

Decimal として表す値。

例外例外
例外の種類条件

OverflowException

value が MaxValue より大きい値か、MinValue より小さい値です。

または

value が Single.NaN、Single.PositiveInfinity、または Single.NegativeInfinity です。

解説解説

このコンストラクタは、value を有効桁数 7 の近似値に丸めます。数字が 7 桁を超える場合でもこの丸めが行われ、7 桁より下位の桁は 0 になります。

使用例使用例

Decimal 構造体を Single 値で初期化するコンストラクタのオーバーロードを使用して、複数の Decimal 数値を作成するコード例を次に示します。

' Example of the Decimal( Single ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module DecimalCtorSDemo

    ' Get the exception type name; remove the namespace prefix.
    Function GetExceptionType( ex As Exception
 ) As String

        Dim exceptionType   As String
 = ex.GetType( ).ToString( )
        Return exceptionType.Substring( _
            exceptionType.LastIndexOf( "."c ) + 1
 )
    End Function

    ' Create a Decimal object and display its value.
    Sub CreateDecimal( value As Single,
 valToStr As String )

        ' Format and display the constructor.
        Console.Write( "{0,-27}", _
            String.Format( "Decimal( {0} )",
 valToStr ) )

        ' Construct the Decimal value.
        Try
            Dim decimalNum As New
 Decimal( value )

            ' Display the value if it was created successfully.
            Console.WriteLine( "{0,31}", decimalNum
 )

        ' Display the exception type if an exception was thrown.
        Catch ex As Exception
            Console.WriteLine( "{0,31}", GetExceptionType(
 ex ) )
        End Try
    End Sub
    
    Sub Main( )

        Console.WriteLine( _
            "This example of the Decimal( Single ) constructor
 " & _
            vbCrLf & "generates the following output."
 & vbCrLf )
        Console.WriteLine( "{0,-27}{1,31}", "Constructor",
 "Value or Exception" )
        Console.WriteLine( "{0,-27}{1,31}", "-----------",
 "------------------" )

        ' Construct Decimal objects from Single values.
        CreateDecimal( 1.2345E+5, "1.2345E+5" )  
              
        CreateDecimal( 1.234567E+15, "1.234567E+15"
 )                
        CreateDecimal( 1.23456789E+25, "1.23456789E+25"
 )                
        CreateDecimal( 1.23456789E+35, "1.23456789E+35"
 )                
        CreateDecimal( 1.2345E-5, "1.2345E-5" )  
              
        CreateDecimal( 1.234567E-15, "1.234567E-15"
 )                
        CreateDecimal( 1.23456789E-25, "1.23456789E-25"
 )                
        CreateDecimal( 1.23456789E-35, "1.23456789E-35"
 )                
        CreateDecimal( 1.0 / 7.0, "1.0 / 7.0" )  
              
    End Sub 
End Module 

' This example of the Decimal( Single ) constructor
' generates the following output.
' 
' Constructor                             Value or Exception
' -----------                             ------------------
' Decimal( 1.2345E+5 )                                123450
' Decimal( 1.234567E+15 )                   1234567000000000
' Decimal( 1.23456789E+25 )       12345680000000000000000000
' Decimal( 1.23456789E+35 )                OverflowException
' Decimal( 1.2345E-5 )                           0.000012345
' Decimal( 1.234567E-15 )            0.000000000000001234567
' Decimal( 1.23456789E-25 )   0.0000000000000000000000001235
' Decimal( 1.23456789E-35 )                                0
' Decimal( 1.0 / 7.0 )                             0.1428571
// Example of the decimal( float ) constructor.
using System;

class DecimalCtorSDemo
{
    // Get the exception type name; remove the namespace prefix.
    public static string
 GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring( 
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Create a decimal object and display its value.
    public static void CreateDecimal(
 float value, string valToStr )
    {
        // Format and display the constructor.
        Console.Write( "{0,-27}", 
            String.Format( "decimal( {0} )", valToStr ) );

        try
        {
            // Construct the decimal value.
            decimal decimalNum = new decimal( value );

            // Display the value if it was created successfully.
            Console.WriteLine( "{0,31}", decimalNum );
        }
        catch( Exception ex )
        {
            // Display the exception type if an exception was thrown.
            Console.WriteLine( "{0,31}", GetExceptionType( ex ) );
        }
    }
    
    public static void Main(
 )
    {

        Console.WriteLine( "This example of the decimal( float
 ) " +
            "constructor \ngenerates the following output.\n" );
        Console.WriteLine( "{0,-27}{1,31}", "Constructor", 
            "Value or Exception" );
        Console.WriteLine( "{0,-27}{1,31}", "-----------", 
            "------------------" );

        // Construct decimal objects from float values.
        CreateDecimal( 1.2345E+5F, "1.2345E+5F" );
        CreateDecimal( 1.234567E+15F, "1.234567E+15F" );
        CreateDecimal( 1.23456789E+25F, "1.23456789E+25F" );
        CreateDecimal( 1.23456789E+35F, "1.23456789E+35F" );
        CreateDecimal( 1.2345E-5F, "1.2345E-5F" );
        CreateDecimal( 1.234567E-15F, "1.234567E-15F" );
        CreateDecimal( 1.23456789E-25F, "1.23456789E-25F" );
        CreateDecimal( 1.23456789E-35F, "1.23456789E-35F" );
        CreateDecimal( 1.0F / 7.0F, "1.0F / 7.0F" );
    }
}

/*
This example of the decimal( float ) constructor
generates the following output.

Constructor                             Value or Exception
-----------                             ------------------
decimal( 1.2345E+5F )                               123450
decimal( 1.234567E+15F )                  1234567000000000
decimal( 1.23456789E+25F )      12345680000000000000000000
decimal( 1.23456789E+35F )               OverflowException
decimal( 1.2345E-5F )                          0.000012345
decimal( 1.234567E-15F )           0.000000000000001234567
decimal( 1.23456789E-25F )  0.0000000000000000000000001235
decimal( 1.23456789E-35F )                               0
decimal( 1.0F / 7.0F )                           0.1428571
*/
// Example of the Decimal( float ) constructor.
using namespace System;

// Get the exception type name; remove the namespace prefix.
String^ GetExceptionType( Exception^ ex )
{
   String^ exceptionType = ex->GetType()->ToString();
   return exceptionType->Substring( exceptionType->LastIndexOf(
 '.' ) + 1 );
}


// Create a Decimal object and display its value.
void CreateDecimal( float value, String^ valToStr
 )
{
   
   // Format and display the constructor.
   Console::Write( "{0,-27}", String::Format( "Decimal( {0} )",
 valToStr ) );
   try
   {
      
      // Construct the Decimal value.
      Decimal decimalNum = Decimal(value);
      
      // Display the value if it was created successfully.
      Console::WriteLine( "{0,31}", decimalNum );
   }
   catch ( Exception^ ex ) 
   {
      
      // Display the exception type if an exception was thrown.
      Console::WriteLine( "{0,31}", GetExceptionType( ex ) );
   }

}

int main()
{
   Console::WriteLine( "This example of the Decimal( float
 ) "
   "constructor \ngenerates the following output.\n" );
   Console::WriteLine( "{0,-27}{1,31}", "Constructor", "Value
 or Exception" );
   Console::WriteLine( "{0,-27}{1,31}", "-----------", "------------------"
 );
   
   // Construct Decimal objects from float values.
   CreateDecimal( 1.2345E+5, "1.2345E+5" );
   CreateDecimal( 1.234567E+15, "1.234567E+15" );
   CreateDecimal( 1.23456789E+25, "1.23456789E+25" );
   CreateDecimal( 1.23456789E+35, "1.23456789E+35" );
   CreateDecimal( 1.2345E-5, "1.2345E-5" );
   CreateDecimal( 1.234567E-15, "1.234567E-15" );
   CreateDecimal( 1.23456789E-25, "1.23456789E-25" );
   CreateDecimal( 1.23456789E-35, "1.23456789E-35" );
   CreateDecimal( 1.0 / 7.0, "1.0 / 7.0" );
}

/*
This example of the Decimal( float ) constructor
generates the following output.

Constructor                             Value or Exception
-----------                             ------------------
Decimal( 1.2345E+5 )                                123450
Decimal( 1.234567E+15 )                   1234567000000000
Decimal( 1.23456789E+25 )       12345680000000000000000000
Decimal( 1.23456789E+35 )                OverflowException
Decimal( 1.2345E-5 )                           0.000012345
Decimal( 1.234567E-15 )            0.000000000000001234567
Decimal( 1.23456789E-25 )   0.0000000000000000000000001235
Decimal( 1.23456789E-35 )                                0
Decimal( 1.0 / 7.0 )                             0.1428571
*/
// Example of the decimal( float ) constructor.
import System.* ;

class DecimalCtorSDemo
{
       // Get the exception type name; remove the namespace prefix.
    public static String GetExceptionType(System.Exception
 ex)
    {
        String exceptionType = ex.GetType().ToString();
        return exceptionType.Substring((exceptionType.LastIndexOf('.')
 + 1));
    } //GetExceptionType

    // Create a decimal object and display its value.
    public static void CreateDecimal(float
 value,String valToStr)
    {
        // Format and display the constructor.
        Console.Write("{0,-27}", String.Format("decimal( {0} )",
 valToStr));
        
        try {
            // Construct the decimal value.
            System.Decimal decimalNum =  new System.Decimal(value);
            
            // Display the value if it was created successfully.
            Console.WriteLine("{0,31}", decimalNum);
        }
        catch(System.Exception  ex) {        
            // Display the exception type if an exception was thrown.
            Console.WriteLine("{0,31}", GetExceptionType(ex));
        }
    } //CreateDecimal

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of the decimal( float
 ) " 
            + "constructor \ngenerates the following output.\n"));
        Console.WriteLine("{0,-27}{1,31}", "Constructor", "Value
 or Exception");
        Console.WriteLine("{0,-27}{1,31}", "-----------", "------------------");
        
        // Construct decimal objects from float values.
        CreateDecimal(123450, "1.2345E+5F");
        CreateDecimal(System.Convert.ToSingle(1.234567E+15), "1.234567E+15F");
        CreateDecimal(System.Convert.ToSingle(1.234568E+25), "1.23456789E+25F");
        CreateDecimal(System.Convert.ToSingle(1.234568E+35), "1.23456789E+35F");
        CreateDecimal(System.Convert.ToSingle(1.2345E-05), "1.2345E-5F");
        CreateDecimal(System.Convert.ToSingle(1.234567E-15), "1.234567E-15F");
        CreateDecimal(System.Convert.ToSingle(1.234568E-25), "1.23456789E-25F");
        CreateDecimal(System.Convert.ToSingle(1.234568E-35), "1.23456789E-35F");
        CreateDecimal(System.Convert.ToSingle(1) /System.Convert.ToSingle(7), 
            "1.0F / 7.0F");
    } //main
} //DecimalCtorSDemo

/*
This example of the decimal( float ) constructor
generates the following output.

Constructor                             Value or Exception
-----------                             ------------------
decimal( 1.2345E+5F )                               123450
decimal( 1.234567E+15F )                  1234567000000000
decimal( 1.23456789E+25F )      12345680000000000000000000
decimal( 1.23456789E+35F )               OverflowException
decimal( 1.2345E-5F )                          0.000012345
decimal( 1.234567E-15F )           0.000000000000001234567
decimal( 1.23456789E-25F )  0.0000000000000000000000001235
decimal( 1.23456789E-35F )                               0
decimal( 1.0F / 7.0F )                           0.1428571
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Decimal コンストラクタ (Int32, Int32, Int32, Boolean, Byte)

Decimal の新しいインスタンスの値を、そのインスタンスの構成部分を指定するパラメータに従って初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    lo As Integer, _
    mid As Integer, _
    hi As Integer, _
    isNegative As Boolean, _
    scale As Byte _
)
Dim lo As Integer
Dim mid As Integer
Dim hi As Integer
Dim isNegative As Boolean
Dim scale As Byte

Dim instance As New Decimal(lo,
 mid, hi, isNegative, scale)
public Decimal (
    int lo,
    int mid,
    int hi,
    bool isNegative,
    byte scale
)
public:
Decimal (
    int lo, 
    int mid, 
    int hi, 
    bool isNegative, 
    unsigned char scale
)
public Decimal (
    int lo, 
    int mid, 
    int hi, 
    boolean isNegative, 
    byte scale
)
public function Decimal (
    lo : int, 
    mid : int, 
    hi : int, 
    isNegative : boolean, 
    scale : byte
)

パラメータ

lo

96 ビット整数の下位 32 ビット。

mid

96 ビット整数の中位 32 ビット。

hi

96 ビット整数の上位 32 ビット。

isNegative

符号。1 は負、0 は正。

scale

0 から 28 までの 10 の指数。

例外例外
例外の種類条件

ArgumentOutOfRangeException

scale が 28 より大きい値です。

解説解説
使用例使用例

Decimal 構造体を Int32 値の 3 つの単語、Boolean 符合、および Byte のスケール ファクタで初期化するコンストラクタのオーバーロードを使用して、複数の Decimal 数値を作成するコード例を次に示します。

' Example of the Decimal( Integer, Integer, Integer, Boolean, Byte )
 
' constructor.
Imports System
Imports Microsoft.VisualBasic

Module DecimalCtorIIIBByDemo

    ' Get the exception type name; remove the namespace prefix.
    Function GetExceptionType( ex As Exception
 ) As String

        Dim exceptionType   As String
 = ex.GetType( ).ToString( )
        Return exceptionType.Substring( _
            exceptionType.LastIndexOf( "."c ) + 1
 )
    End Function

    ' Create a Decimal object and display its value.
    Sub CreateDecimal( low As Integer,
 mid As Integer, _
        high As Integer, isNeg As
 Boolean, scale as Byte
 )

        ' Format the constructor for display.
        Dim ctor As String
 = String.Format( _
            "Decimal( {0}, {1}, {2}, {3}, {4} )",
 _
            low, mid, high, isNeg, scale )
        Dim valOrExc As String

        ' Construct the Decimal value.
        Try
            Dim decimalNum As New
 Decimal( _
                low, mid, high, isNeg, scale )

            ' Format and save the Decimal value.
            valOrExc = decimalNum.ToString( )

        ' Save the exception type if an exception was thrown.
        Catch ex As Exception
            valOrExc =  GetExceptionType( ex ) 
        End Try

        ' Display the constructor and Decimal value or exception.
        Dim ctorLen = 76 - valOrExc.Length
        If ctorLen > ctor.Length Then

            ' Display the data on one line if it will fit.
            Console.WriteLine( "{0}{1}", ctor.PadRight(
 ctorLen ), _
                valOrExc )

        ' Otherwise, display the data on two lines.
        Else
            Console.WriteLine( "{0}", ctor )
            Console.WriteLine( "{0,76}", valOrExc
 )
        End If
    End Sub
    
    Sub Main( )

        Console.WriteLine( _
            "This example of the Decimal( Integer, Integer, "
 & _
            "Integer, Boolean, Byte ) " & vbCrLf
 & "constructor " & _
            "generates the following output." &
 vbCrLf )
        Console.WriteLine( "{0,-38}{1,38}", "Constructor",
 _
            "Value or Exception" )
        Console.WriteLine( "{0,-38}{1,38}", "-----------",
 _
            "------------------" )

        ' Construct Decimal objects from the component fields.
        CreateDecimal( 0, 0, 0, False, 0 )                
        CreateDecimal( 0, 0, 0, False, 27 )                
        CreateDecimal( 0, 0, 0, True, 0 )                
        CreateDecimal( 1000000000, 0, 0, False, 0 )          
      
        CreateDecimal( 0, 1000000000, 0, False, 0 )          
      
        CreateDecimal( 0, 0, 1000000000, False, 0 )          
      
        CreateDecimal( 1000000000, 1000000000, 1000000000, False,
 0 )
        CreateDecimal( -1, -1, -1, False, 0 )                
        CreateDecimal( -1, -1, -1, True, 0 )                
        CreateDecimal( -1, -1, -1, False, 15 )               
 
        CreateDecimal( -1, -1, -1, False, 28 )               
 
        CreateDecimal( -1, -1, -1, False, 29 )               
 
        CreateDecimal( Integer.MaxValue, 0, 0, False,
 18 )                
        CreateDecimal( Integer.MaxValue, 0, 0, False,
 28 )                
        CreateDecimal( Integer.MaxValue, 0, 0, True,
 28 )                
    End Sub 
End Module 

' This example of the Decimal( Integer, Integer, Integer, Boolean, Byte
 )
' constructor generates the following output.
' 
' Constructor                                               Value or
 Exception
' -----------                                               ------------------
' Decimal( 0, 0, 0, False, 0 )                                     
          0
' Decimal( 0, 0, 0, False, 27 )                                    
          0
' Decimal( 0, 0, 0, True, 0 )                                      
          0
' Decimal( 1000000000, 0, 0, False, 0 )                            
 1000000000
' Decimal( 0, 1000000000, 0, False, 0 )                    4294967296000000000
' Decimal( 0, 0, 1000000000, False, 0 )          18446744073709551616000000000
' Decimal( 1000000000, 1000000000, 1000000000, False, 0 )
'                                                18446744078004518913000000000
' Decimal( -1, -1, -1, False, 0 )                79228162514264337593543950335
' Decimal( -1, -1, -1, True, 0 )                -79228162514264337593543950335
' Decimal( -1, -1, -1, False, 15 )              79228162514264.337593543950335
' Decimal( -1, -1, -1, False, 28 )              7.9228162514264337593543950335
' Decimal( -1, -1, -1, False, 29 )                 ArgumentOutOfRangeException
' Decimal( 2147483647, 0, 0, False, 18 )                  0.000000002147483647
' Decimal( 2147483647, 0, 0, False, 28 )        0.0000000000000000002147483647
' Decimal( 2147483647, 0, 0, True, 28 )        -0.0000000000000000002147483647
// Example of the decimal( int, int, int, bool, byte ) constructor.
using System;

class DecimalCtorIIIBByDemo
{
    // Get the exception type name; remove the namespace prefix.
    public static string
 GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring( 
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Create a decimal object and display its value.
    public static void CreateDecimal(
 int low, int mid, int
 high, 
        bool isNeg, byte scale )
    {
        // Format the constructor for display.
        string ctor = String.Format( 
            "decimal( {0}, {1}, {2}, {3}, {4} )", 
            low, mid, high, isNeg, scale );
        string valOrExc;

        try
        {
            // Construct the decimal value.
            decimal decimalNum = new decimal( 
                low, mid, high, isNeg, scale );

            // Format and save the decimal value.
            valOrExc = decimalNum.ToString( );
        }
        catch( Exception ex )
        {
            // Save the exception type if an exception was thrown.
            valOrExc = GetExceptionType( ex );
        }

        // Display the constructor and decimal value or exception.
        int ctorLen = 76 - valOrExc.Length;

        // Display the data on one line if it will fit.
        if ( ctorLen > ctor.Length )
            Console.WriteLine( "{0}{1}", ctor.PadRight( ctorLen ), 
                valOrExc );

        // Otherwise, display the data on two lines.
        else
        {
            Console.WriteLine( "{0}", ctor );
            Console.WriteLine( "{0,76}", valOrExc );
        }
    }
    
    public static void Main(
 )
    {

        Console.WriteLine( "This example of the decimal( int,
 int, " +
            "int, bool, byte ) \nconstructor
 " +
            "generates the following output.\n" );
        Console.WriteLine( "{0,-38}{1,38}", "Constructor", 
            "Value or Exception" );
        Console.WriteLine( "{0,-38}{1,38}", "-----------", 
            "------------------" );

        // Construct decimal objects from the component fields.
        CreateDecimal( 0, 0, 0, false, 0 );
        CreateDecimal( 0, 0, 0, false, 27 );
        CreateDecimal( 0, 0, 0, true, 0 );
        CreateDecimal( 1000000000, 0, 0, false, 0 );
        CreateDecimal( 0, 1000000000, 0, false, 0 );
        CreateDecimal( 0, 0, 1000000000, false, 0 );
        CreateDecimal( 1000000000, 1000000000, 1000000000, false,
 0 );
        CreateDecimal( -1, -1, -1, false, 0 );
        CreateDecimal( -1, -1, -1, true, 0 );
        CreateDecimal( -1, -1, -1, false, 15 );
        CreateDecimal( -1, -1, -1, false, 28 );
        CreateDecimal( -1, -1, -1, false, 29 );
        CreateDecimal( int.MaxValue, 0, 0, false,
 18 );
        CreateDecimal( int.MaxValue, 0, 0, false,
 28 );
        CreateDecimal( int.MaxValue, 0, 0, true,
 28 );
    }
}

/*
This example of the decimal( int, int, int,
 bool, byte )
constructor generates the following output.

Constructor                                               Value or Exception
-----------                                               ------------------
decimal( 0, 0, 0, False, 0 )                                               0
decimal( 0, 0, 0, False, 27 )                                              0
decimal( 0, 0, 0, True, 0 )                                                0
decimal( 1000000000, 0, 0, False, 0 )                             1000000000
decimal( 0, 1000000000, 0, False, 0 )                    4294967296000000000
decimal( 0, 0, 1000000000, False, 0 )          18446744073709551616000000000
decimal( 1000000000, 1000000000, 1000000000, False, 0 )
                                               18446744078004518913000000000
decimal( -1, -1, -1, False, 0 )                79228162514264337593543950335
decimal( -1, -1, -1, True, 0 )                -79228162514264337593543950335
decimal( -1, -1, -1, False, 15 )              79228162514264.337593543950335
decimal( -1, -1, -1, False, 28 )              7.9228162514264337593543950335
decimal( -1, -1, -1, False, 29 )                 ArgumentOutOfRangeException
decimal( 2147483647, 0, 0, False, 18 )                  0.000000002147483647
decimal( 2147483647, 0, 0, False, 28 )        0.0000000000000000002147483647
decimal( 2147483647, 0, 0, True, 28 )        -0.0000000000000000002147483647
*/
// Example of the Decimal( int, int, int, bool, unsigned char ) 
// constructor.
using namespace System;

// Get the exception type name; remove the namespace prefix.
String^ GetExceptionType( Exception^ ex )
{
   String^ exceptionType = ex->GetType()->ToString();
   return exceptionType->Substring( exceptionType->LastIndexOf(
 '.' ) + 1 );
}


// Create a Decimal object and display its value.
void CreateDecimal( int low, int
 mid, int high, bool isNeg, unsigned char
 scale )
{
   
   // Format the constructor for display.
   array<Object^>^boxedParams = gcnew array<Object^>(5);
   boxedParams[ 0 ] = low;
   boxedParams[ 1 ] = mid;
   boxedParams[ 2 ] = high;
   boxedParams[ 3 ] = isNeg;
   boxedParams[ 4 ] = scale;
   String^ ctor = String::Format( "Decimal( {0}, {1}, {2}, {3}, {4} )",
 boxedParams );
   String^ valOrExc;
   try
   {
      
      // Construct the Decimal value.
      Decimal decimalNum = Decimal(low,mid,high,isNeg,scale);
      
      // Format and save the Decimal value.
      valOrExc = decimalNum.ToString();
   }
   catch ( Exception^ ex ) 
   {
      
      // Save the exception type if an exception was thrown.
      valOrExc = GetExceptionType( ex );
   }

   
   // Display the constructor and Decimal value or exception.
   int ctorLen = 76 - valOrExc->Length;
   
   // Display the data on one line if it will fit.
   if ( ctorLen > ctor->Length )
      Console::WriteLine( "{0}{1}", ctor->PadRight( ctorLen ), valOrExc
 );
   // Otherwise, display the data on two lines.
   else
   {
      Console::WriteLine( "{0}", ctor );
      Console::WriteLine( "{0,76}", valOrExc );
   }
}

int main()
{
   Console::WriteLine( "This example of the Decimal( int,
 int, "
   "int, bool, unsigned char
 ) \nconstructor "
   "generates the following output.\n" );
   Console::WriteLine( "{0,-38}{1,38}", "Constructor", "Value
 or Exception" );
   Console::WriteLine( "{0,-38}{1,38}", "-----------", "------------------"
 );
   
   // Construct Decimal objects from double values.
   CreateDecimal( 0, 0, 0, false, 0 );
   CreateDecimal( 0, 0, 0, false, 27 );
   CreateDecimal( 0, 0, 0, true, 0 );
   CreateDecimal( 1000000000, 0, 0, false, 0 );
   CreateDecimal( 0, 1000000000, 0, false, 0 );
   CreateDecimal( 0, 0, 1000000000, false, 0 );
   CreateDecimal( 1000000000, 1000000000, 1000000000, false, 0
 );
   CreateDecimal(  -1, -1, -1, false, 0 );
   CreateDecimal(  -1, -1, -1, true, 0 );
   CreateDecimal(  -1, -1, -1, false, 15 );
   CreateDecimal(  -1, -1, -1, false, 28 );
   CreateDecimal(  -1, -1, -1, false, 29 );
   CreateDecimal( Int32::MaxValue, 0, 0, false, 18 );
   CreateDecimal( Int32::MaxValue, 0, 0, false, 28 );
   CreateDecimal( Int32::MaxValue, 0, 0, true, 28 );
}

/*
This example of the Decimal( int, int, int,
 bool, unsigned char )
constructor generates the following output.

Constructor                                               Value or Exception
-----------                                               ------------------
Decimal( 0, 0, 0, False, 0 )                                               0
Decimal( 0, 0, 0, False, 27 )                                              0
Decimal( 0, 0, 0, True, 0 )                                                0
Decimal( 1000000000, 0, 0, False, 0 )                             1000000000
Decimal( 0, 1000000000, 0, False, 0 )                    4294967296000000000
Decimal( 0, 0, 1000000000, False, 0 )          18446744073709551616000000000
Decimal( 1000000000, 1000000000, 1000000000, False, 0 )
                                               18446744078004518913000000000
Decimal( -1, -1, -1, False, 0 )                79228162514264337593543950335
Decimal( -1, -1, -1, True, 0 )                -79228162514264337593543950335
Decimal( -1, -1, -1, False, 15 )              79228162514264.337593543950335
Decimal( -1, -1, -1, False, 28 )              7.9228162514264337593543950335
Decimal( -1, -1, -1, False, 29 )                 ArgumentOutOfRangeException
Decimal( 2147483647, 0, 0, False, 18 )                  0.000000002147483647
Decimal( 2147483647, 0, 0, False, 28 )        0.0000000000000000002147483647
Decimal( 2147483647, 0, 0, True, 28 )        -0.0000000000000000002147483647
*/
// Example of the decimal( int, int, int, bool, byte ) constructor.
import System.* ;

class DecimalCtorIIIBByDemo
{
    // Get the exception type name; remove the namespace prefix.
    public static String GetExceptionType(System.Exception
 ex)
    {
        String exceptionType = ex.GetType().ToString();
        return exceptionType.Substring((exceptionType.LastIndexOf('.')
 + 1));
    } //GetExceptionType

    // Create a decimal object and display its value.
    public static void CreateDecimal(int
 low, int mid, 
        int high, boolean isNeg, ubyte scale)
    {
        // Format the constructor for display.
        String ctor = String.Format("decimal( {0}, {1}, {2}, {3}, {4} )"
,
                    new Object[] { new Integer(low),
 new Integer(mid),
                    new Integer(high), (System.Boolean)(isNeg),
 
                    new Integer(scale) });
        String valOrExc;

        try {
            // Construct the decimal value.
            System.Decimal decimalNum = new System.Decimal(low,
 mid, high, 
                                        isNeg, scale);

            // Format and save the decimal value.
            valOrExc = decimalNum.ToString();
        }
        catch (System.Exception ex)    {
            // Save the exception type if an exception was thrown.
            valOrExc = System.Convert.ToString(GetExceptionType(ex));
        }

        // Display the constructor and decimal value or exception.
        int ctorLen = 76 - valOrExc.get_Length();

        // Display the data on one line if it will fit.
        if (ctorLen > ctor.get_Length()) {
            Console.WriteLine("{0}{1}", ctor.PadRight(ctorLen), valOrExc);
        }
        // Otherwise, display the data on two lines.
        else {
            Console.WriteLine("{0}", ctor);
            Console.WriteLine("{0,76}", valOrExc);
        }
    } //CreateDecimal

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of the decimal( int,
 int, " 
            + "int, bool, byte ) \nconstructor
 "
            + "generates the following output.\n"));
        Console.WriteLine("{0,-38}{1,38}", "Constructor", "Value
 or Exception");
        Console.WriteLine("{0,-38}{1,38}", "-----------", "------------------");

        // Construct decimal objects from the component fields.
        CreateDecimal(0, 0, 0, false, (ubyte)(0));
        CreateDecimal(0, 0, 0, false, (ubyte)27);
        CreateDecimal(0, 0, 0, true, (ubyte)0);
        CreateDecimal(1000000000, 0, 0, false, (ubyte)0);
        CreateDecimal(0, 1000000000, 0, false, (ubyte)0);
        CreateDecimal(0, 0, 1000000000, false, (ubyte)0);
        CreateDecimal(1000000000, 1000000000, 1000000000, false,
 (ubyte)0);
        CreateDecimal(-1, -1, -1, false, (ubyte)0);
        CreateDecimal(-1, -1, -1, true, (ubyte)0);
        CreateDecimal(-1, -1, -1, false, (ubyte)15);
        CreateDecimal(-1, -1, -1, false, (ubyte)28);
        CreateDecimal(-1, -1, -1, false, (ubyte)29);
        CreateDecimal(Integer.MAX_VALUE, 0, 0, false, (ubyte)18);
        CreateDecimal(Integer.MAX_VALUE, 0, 0, false, (ubyte)28);
        CreateDecimal(Integer.MAX_VALUE, 0, 0, true, (ubyte)28);
    } //main
} //DecimalCtorIIIBByDemo

/*
This example of the decimal( int, int, int,
 bool, byte )
constructor generates the following output.

Constructor                                               Value or Exception
-----------                                               ------------------
decimal( 0, 0, 0, False, 0 )                                               0
decimal( 0, 0, 0, False, 27 )                                              0
decimal( 0, 0, 0, True, 0 )                                                0
decimal( 1000000000, 0, 0, False, 0 )                             1000000000
decimal( 0, 1000000000, 0, False, 0 )                    4294967296000000000
decimal( 0, 0, 1000000000, False, 0 )          18446744073709551616000000000
decimal( 1000000000, 1000000000, 1000000000, False, 0 )
                                               18446744078004518913000000000
decimal( -1, -1, -1, False, 0 )                79228162514264337593543950335
decimal( -1, -1, -1, True, 0 )                -79228162514264337593543950335
decimal( -1, -1, -1, False, 15 )              79228162514264.337593543950335
decimal( -1, -1, -1, False, 28 )              7.9228162514264337593543950335
decimal( -1, -1, -1, False, 29 )                 ArgumentOutOfRangeException
decimal( 2147483647, 0, 0, False, 18 )                  0.000000002147483647
decimal( 2147483647, 0, 0, False, 28 )        0.0000000000000000002147483647
decimal( 2147483647, 0, 0, True, 28 )        -0.0000000000000000002147483647
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Decimal コンストラクタ (Int64)

Decimal の新しいインスタンスを作成し、その値を、指定した 64 ビット符号付き整数に設定します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

public Decimal (
    long value
)
public:
Decimal (
    long long value
)
public Decimal (
    long value
)

パラメータ

value

Decimal として表す値。

使用例使用例

Decimal 構造体を Int64 値で初期化するコンストラクタのオーバーロードを使用して、複数の Decimal 数値を作成するコード例を次に示します。

' Example of the Decimal( Long ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module DecimalCtorLDemo

    ' Create a Decimal object and display its value.
    Sub CreateDecimal( value As Long,
 valToStr As String )

        Dim decimalNum As New
 Decimal( value )

        ' Format the constructor for display.
        Dim ctor As String
 = _
            String.Format( "Decimal( {0} )",
 valToStr )

        ' Display the constructor and its value.
        Console.WriteLine( "{0,-30}{1,22}", ctor,
 decimalNum )
    End Sub
    
    Sub Main( )

        Console.WriteLine( _
            "This example of the Decimal( Long ) constructor "
 & _
            vbCrLf & "generates the following output."
 & vbCrLf )
        Console.WriteLine( "{0,-30}{1,22}", "Constructor",
 "Value" )
        Console.WriteLine( "{0,-30}{1,22}", "-----------",
 "-----" )

        ' Construct Decimal objects from Long values.
        CreateDecimal( Long.MinValue, "Long.MinValue"
 )                
        CreateDecimal( Long.MaxValue, "Long.MaxValue"
 )                
        CreateDecimal( 0L, "0" )                
        CreateDecimal( 999999999999999999, "999999999999999999"
 )                
        CreateDecimal( &H2000000000000000, "&H2000000000000000"
 )                
        CreateDecimal( &HE000000000000000, "&HE000000000000000"
 )                
    End Sub 
End Module 

' This example of the Decimal( Long ) constructor
' generates the following output.
' 
' Constructor                                    Value
' -----------                                    -----
' Decimal( Long.MinValue )        -9223372036854775808
' Decimal( Long.MaxValue )         9223372036854775807
' Decimal( 0 )                                       0
' Decimal( 999999999999999999 )     999999999999999999
' Decimal( &H2000000000000000 )    2305843009213693952
' Decimal( &HE000000000000000 )   -2305843009213693952
// Example of the decimal( long ) constructor.
using System;

class DecimalCtorLDemo
{
    // Create a decimal object and display its value.
    public static void CreateDecimal(
 long value, string valToStr )
    {
        decimal decimalNum = new decimal( value );

        // Format the constructor for display.
        string ctor = String.Format( "decimal( {0} )",
 valToStr );

        // Display the constructor and its value.
        Console.WriteLine( "{0,-35}{1,22}", ctor, decimalNum );
    }
    
    public static void Main(
 )
    {
        Console.WriteLine( "This example of the decimal( long ) " +
            "constructor \ngenerates the following output.\n" );
        Console.WriteLine( "{0,-35}{1,22}", "Constructor", "Value"
 );
        Console.WriteLine( "{0,-35}{1,22}", "-----------", "-----"
 );

        // Construct decimal objects from long values.
        CreateDecimal( long.MinValue, "long.MinValue" );
        CreateDecimal( long.MaxValue, "long.MaxValue" );
        CreateDecimal( 0L, "0L" );
        CreateDecimal( 999999999999999999, "999999999999999999" );
        CreateDecimal( 0x2000000000000000, "0x2000000000000000" );
        CreateDecimal( unchecked( (long)0xE000000000000000 ), 
            "(long)0xE000000000000000" );
    }
}

/*
This example of the decimal( long ) constructor
generates the following output.

Constructor                                         Value
-----------                                         -----
decimal( long.MinValue )             -9223372036854775808
decimal( long.MaxValue )              9223372036854775807
decimal( 0 )                                            0
decimal( 999999999999999999 )          999999999999999999
decimal( 0x2000000000000000 )         2305843009213693952
decimal( (long)0xE000000000000000 )  -2305843009213693952
*/
// Example of the Decimal( __int64 ) constructor.
using namespace System;

// Create a Decimal object and display its value.
void CreateDecimal( __int64 value, String^ valToStr )
{
   Decimal decimalNum = Decimal(value);
   
   // Format the constructor for display.
   String^ ctor = String::Format( "Decimal( {0} )", valToStr );
   
   // Display the constructor and its value.
   Console::WriteLine( "{0,-35}{1,22}", ctor, decimalNum );
}

int main()
{
   Console::WriteLine( "This example of the Decimal( __int64 ) "
   "constructor \ngenerates the following output.\n" );
   Console::WriteLine( "{0,-35}{1,22}", "Constructor", "Value"
 );
   Console::WriteLine( "{0,-35}{1,22}", "-----------", "-----"
 );
   
   // Construct Decimal objects from __int64 values.
   CreateDecimal( Int64::MinValue, "Int64::MinValue" );
   CreateDecimal( Int64::MaxValue, "Int64::MaxValue" );
   CreateDecimal( 0, "0" );
   CreateDecimal( 999999999999999999, "999999999999999999" );
   CreateDecimal( 0x2000000000000000, "0x2000000000000000" );
   CreateDecimal( 0xE000000000000000, "0xE000000000000000" );
}

/*
This example of the Decimal( __int64 ) constructor
generates the following output.

Constructor                                         Value
-----------                                         -----
Decimal( Int64::MinValue )           -9223372036854775808
Decimal( Int64::MaxValue )            9223372036854775807
Decimal( 0 )                                            0
Decimal( 999999999999999999 )          999999999999999999
Decimal( 0x2000000000000000 )         2305843009213693952
Decimal( 0xE000000000000000 )        -2305843009213693952
*/
// Example of the decimal( long ) constructor.
import System.* ;

class DecimalCtorLDemo
{   
    // Create a decimal object and display its value.
    public static void CreateDecimal(long
 value, String valToStr)
    {
        System.Decimal decimalNum =  new System.Decimal(value);
        
        // Format the constructor for display.
        String ctor = String.Format("decimal( {0} )", valToStr);
        
        // Display the constructor and its value.
        Console.WriteLine("{0,-35}{1,22}", ctor, decimalNum);
    } //CreateDecimal
        
    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of the decimal( long ) " 
            + "constructor \ngenerates the following output.\n"));
        Console.WriteLine("{0,-35}{1,22}", "Constructor", "Value");
        Console.WriteLine("{0,-35}{1,22}", "-----------", "-----");
        
        // Construct decimal objects from long values.
        CreateDecimal(Long.MIN_VALUE, "long.MinValue");
        CreateDecimal(Long.MAX_VALUE, "long.MaxValue");
        CreateDecimal(0L, "0");
        CreateDecimal(999999999999999999L, "999999999999999999");
        CreateDecimal(0x2000000000000000L, "0x2000000000000000");
        CreateDecimal((long)(0xE000000000000000L), "(long)0xE000000000000000");
    } //main
} //DecimalCtorLDemo

/*
This example of the decimal( long ) constructor
generates the following output.

Constructor                                         Value
-----------                                         -----
decimal( long.MinValue )             -9223372036854775808
decimal( long.MaxValue )              9223372036854775807
decimal( 0 )                                            0
decimal( 999999999999999999 )          999999999999999999
decimal( 0x2000000000000000 )         2305843009213693952
decimal( (long)0xE000000000000000 )  -2305843009213693952
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Decimal コンストラクタ (Int32)

Decimal の新しいインスタンスを作成し、その値を、指定した 32 ビット符号付き整数に設定します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

public Decimal (
    int value
)
public:
Decimal (
    int value
)
public Decimal (
    int value
)

パラメータ

value

Decimal として表す値。

使用例使用例

Decimal 構造体を Int32 値で初期化するコンストラクタのオーバーロードを使用して、複数の Decimal 数値を作成するコード例を次に示します。

' Example of the Decimal( Integer ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module DecimalCtorIDemo

    ' Create a Decimal object and display its value.
    Sub CreateDecimal( value As Integer,
 valToStr As String )

        Dim decimalNum As New
 Decimal( value )

        ' Format the constructor for display.
        Dim ctor As String
 = _
            String.Format( "Decimal( {0} )",
 valToStr )

        ' Display the constructor and its value.
        Console.WriteLine( "{0,-33}{1,16}", ctor,
 decimalNum )
    End Sub
    
    Sub Main( )

        Console.WriteLine( _
            "This example of the Decimal( Integer ) constructor
 " & _
            vbCrLf & "generates the following output."
 & vbCrLf )
        Console.WriteLine( "{0,-33}{1,16}", "Constructor",
 "Value" )
        Console.WriteLine( "{0,-33}{1,16}", "-----------",
 "-----" )

        ' Construct Decimal objects from Integer values.
        CreateDecimal( Integer.MinValue, "Integer.MinValue"
 )                
        CreateDecimal( Integer.MaxValue, "Integer.MaxValue"
 )                
        CreateDecimal( 0, "0" )                
        CreateDecimal( 999999999, "999999999" )  
              
        CreateDecimal( &H40000000, "&H40000000"
 )                
        CreateDecimal( &HC0000000, "&HC0000000"
 )                
    End Sub 
End Module 

' This example of the Decimal( Integer ) constructor
' generates the following output.
' 
' Constructor                                 Value
' -----------                                 -----
' Decimal( Integer.MinValue )           -2147483648
' Decimal( Integer.MaxValue )            2147483647
' Decimal( 0 )                                    0
' Decimal( 999999999 )                    999999999
' Decimal( &H40000000 )                  1073741824
' Decimal( &HC0000000 )                 -1073741824
// Example of the decimal( int ) constructor.
using System;

class DecimalCtorIDemo
{
    // Create a decimal object and display its value.
    public static void CreateDecimal(
 int value, string valToStr )
    {
        decimal decimalNum = new decimal( value );

        // Format the constructor for display.
        string ctor = String.Format( "decimal( {0} )",
 valToStr );

        // Display the constructor and its value.
        Console.WriteLine( "{0,-30}{1,16}", ctor, decimalNum );
    }
    
    public static void Main(
 )
    {
        Console.WriteLine( "This example of the decimal( int
 ) " +
            "constructor \ngenerates the following output.\n" );
        Console.WriteLine( "{0,-30}{1,16}", "Constructor", "Value"
 );
        Console.WriteLine( "{0,-30}{1,16}", "-----------", "-----"
 );

        // Construct decimal objects from int values.
        CreateDecimal( int.MinValue, "int.MinValue"
 );
        CreateDecimal( int.MaxValue, "int.MaxValue"
 );
        CreateDecimal( 0, "0" );
        CreateDecimal( 999999999, "999999999" );
        CreateDecimal( 0x40000000, "0x40000000" );
        CreateDecimal( unchecked( (int)0xC0000000 ), 
            "(int)0xC0000000" );
    }
}

/*
This example of the decimal( int ) constructor
generates the following output.

Constructor                              Value
-----------                              -----
decimal( int.MinValue )            -2147483648
decimal( int.MaxValue )             2147483647
decimal( 0 )                                 0
decimal( 999999999 )                 999999999
decimal( 0x40000000 )               1073741824
decimal( (int)0xC0000000 )         -1073741824
*/
// Example of the Decimal( int ) constructor.
using namespace System;

// Create a Decimal object and display its value.
void CreateDecimal( int value, String^ valToStr
 )
{
   Decimal decimalNum = Decimal(value);
   
   // Format the constructor for display.
   String^ ctor = String::Format( "Decimal( {0} )", valToStr );
   
   // Display the constructor and its value.
   Console::WriteLine( "{0,-30}{1,16}", ctor, decimalNum );
}

int main()
{
   Console::WriteLine( "This example of the Decimal( int
 ) "
   "constructor \ngenerates the following output.\n" );
   Console::WriteLine( "{0,-30}{1,16}", "Constructor", "Value"
 );
   Console::WriteLine( "{0,-30}{1,16}", "-----------", "-----"
 );
   
   // Construct Decimal objects from int values.
   CreateDecimal( Int32::MinValue, "Int32::MinValue" );
   CreateDecimal( Int32::MaxValue, "Int32::MaxValue" );
   CreateDecimal( 0, "0" );
   CreateDecimal( 999999999, "999999999" );
   CreateDecimal( 0x40000000, "0x40000000" );
   CreateDecimal( (int)0xC0000000, "(int)0xC0000000"
 );
}

/*
This example of the Decimal( int ) constructor
generates the following output.

Constructor                              Value
-----------                              -----
Decimal( Int32::MinValue )         -2147483648
Decimal( Int32::MaxValue )          2147483647
Decimal( 0 )                                 0
Decimal( 999999999 )                 999999999
Decimal( 0x40000000 )               1073741824
Decimal( (int)0xC0000000 )         -1073741824
*/
// Example of the decimal( int ) constructor.
import System.* ;

class DecimalCtorIDemo
{
    // Create a decimal object and display its value.
    public static void CreateDecimal(int
 value, String valToStr)
    {
        System.Decimal decimalNum = new System.Decimal(value);

        // Format the constructor for display.
        String ctor = String.Format("decimal( {0} )", valToStr);

        // Display the constructor and its value.
        Console.WriteLine("{0,-35}{1,22}", ctor, decimalNum);
    } //CreateDecimal

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of the decimal( int
 ) "
            + "constructor \ngenerates the following output.\n"));
        Console.WriteLine("{0,-35}{1,22}", "Constructor", "Value");
        Console.WriteLine("{0,-35}{1,22}", "-----------", "-----");

        // Construct decimal objects from long values.
        CreateDecimal(Integer.MIN_VALUE, "int.MinValue");
        CreateDecimal(Integer.MAX_VALUE, "int.MaxValue");
        CreateDecimal(0, "0");
        CreateDecimal(999999999, "999999999");
        CreateDecimal(0x40000000, "0x40000000");
        CreateDecimal(((int)0xC0000000), "(int)0xC0000000");
    } //main
} //DecimalCtorLDemo

/*
This example of the decimal( int ) constructor
generates the following output.

Constructor                              Value
-----------                              -----
decimal( int.MinValue )            -2147483648
decimal( int.MaxValue )             2147483647
decimal( 0 )                                 0
decimal( 999999999 )                 999999999
decimal( 0x40000000 )               1073741824
decimal( (int)0xC0000000 )         -1073741824
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Decimal コンストラクタ

Decimal の新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
Decimal (Double) Decimal の新しいインスタンスを作成し、その値を、指定した倍精度浮動小数点数に設定します。

.NET Compact Framework によってサポートされています。

Decimal (Int32) Decimal の新しいインスタンスを作成し、その値を、指定した 32 ビット符号付き整数に設定します。

.NET Compact Framework によってサポートされています。

Decimal (Int32[]) Decimal の新しいインスタンスの値を、指定した配列に格納されている、バイナリ形式の 10 進値に初期化します。

.NET Compact Framework によってサポートされています。

Decimal (Int64) Decimal の新しいインスタンスを作成し、その値を、指定した 64 ビット符号付き整数に設定します。

.NET Compact Framework によってサポートされています。

Decimal (Single) Decimal の新しいインスタンスを作成し、その値を、指定した単精度浮動小数点数に設定します。

.NET Compact Framework によってサポートされています。

Decimal (UInt32) Decimal の新しいインスタンスを作成して、その値を、指定した 32 ビット符号なし整数に設定します。

.NET Compact Framework によってサポートされています。

Decimal (UInt64) Decimal の新しいインスタンスを作成して、その値を、指定した 64 ビット符号なし整数に設定します。

.NET Compact Framework によってサポートされています。

Decimal (Int32, Int32, Int32, Boolean, Byte) Decimal の新しいインスタンスの値を、そのインスタンスの構成部分を指定するパラメータに従って初期化します。

.NET Compact Framework によってサポートされています。

参照参照

関連項目

Decimal 構造体
Decimal メンバ
System 名前空間

Decimal コンストラクタ (Int32[])

Decimal の新しいインスタンスの値を、指定した配列に格納されている、バイナリ形式の 10 進値に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外の種類条件

ArgumentNullException

bits が null 参照 (Visual Basic では Nothing) です。

ArgumentException

bits の長さが 4 ではありません。

または

bits の 10 進値形式が有効ではありません。

解説解説

Decimal 数値のバイナリ表現は、1 ビットの符号、96 ビットの整数、および整数値を除算し、小数部を指定するために使用するスケール ファクタから構成されます。スケール ファクタは黙示的に数値 10 になり、0 から 28 の範囲の指数で累乗されます。

bits は、32 ビット符号付き整数の 4 要素長配列です。

bits [0]、bits [1]、および bits [2] は、96 ビット整数の下位 32 ビット、中位 32 ビット、および上位 32 ビットをそれぞれ格納しています。

bits [3] はスケール ファクタと符号を格納し、次に示す部分から構成されます。

ビット 0 ~ 15 の下位ワードは未使用で、0 である必要があります。

ビット 16 ~ 23 には、0 から 28 までの範囲の指数部を格納する必要があります。この指数部は、整数を除算する 10 の累乗を示します。

ビット 24 ~ 30 は未使用で、0 である必要があります。

ビット 31 は符号を格納している必要があります。0 は正、1 は負を表します。

1 つの数値に有効なバイナリ形式がいくつかある場合があり、すべての形式は等しく有効であり、数値として等価です。ビット形式では負の 0 と正の 0 が区別されます。これらの値はすべての演算で等値として扱われます。

使用例使用例

Decimal 構造体を 4 つの Int32 値の配列で初期化するコンストラクタのオーバーロードを使用して、複数の Decimal 数値を作成するコード例を次に示します。

' Example of the Decimal( Integer( ) ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module DecimalCtorIArrDemo

    ' Get the exception type name; remove the namespace prefix.
    Function GetExceptionType( ex As Exception
 ) As String

        Dim exceptionType   As String
 = ex.GetType( ).ToString( )
        Return exceptionType.Substring( _
            exceptionType.LastIndexOf( "."c ) + 1
 )
    End Function

    ' Create a Decimal object and display its value.
    Sub CreateDecimal( ByVal bits( ) As
 Integer )

        ' Format and save the constructor.
        Dim ctor As String
 = String.Format( "Decimal( {{ &H{0:X}",
 bits( 0 ) )
        Dim valOrExc As String
        Dim index As Integer
        For index = 1 to bits.Length - 1
            ctor &= String.Format( ", &H{0:X}",
 bits( index ) )
        Next index
        ctor &= " } )"

        ' Construct the Decimal value.
        Try
            Dim decimalNum As New
 Decimal( bits )

            ' Format the Decimal value for display.
            valOrExc = decimalNum.ToString( )

        ' Save the exception type if an exception was thrown.
        Catch ex As Exception
            valOrExc =  GetExceptionType( ex ) 
        End Try

        ' Display the constructor and Decimal value or exception.
        Dim ctorLen As Integer
 = 76 - valOrExc.Length
        If ctorLen > ctor.Length Then

            ' Display the data on one line if it will fit.
            Console.WriteLine( "{0}{1}", ctor.PadRight(
 ctorLen ), _
                valOrExc )

        ' Otherwise, display the data on two lines.
        Else
            Console.WriteLine( "{0}", ctor )
            Console.WriteLine( "{0,76}", valOrExc
 )
        End If
    End Sub
    
    Sub Main( )

        Console.WriteLine( "This example of the "
 & _
            "Decimal( Integer( ) ) constructor " &
 _
            vbCrLf & "generates the following output."
 & vbCrLf )
        Console.WriteLine( "{0,-38}{1,38}", "Constructor",
 _
            "Value or Exception" )
        Console.WriteLine( "{0,-38}{1,38}", "-----------",
 _
            "------------------" )

        ' Construct Decimal objects from Integer arrays.
        CreateDecimal( New Integer( ) { 0,
 0, 0, 0 } )
        CreateDecimal( New Integer( ) { 0,
 0, 0 } )
        CreateDecimal( New Integer( ) { 0,
 0, 0, 0, 0 } )
        CreateDecimal( New Integer( ) { 1000000000,
 0, 0, 0 } )
        CreateDecimal( New Integer( ) { 0,
 1000000000, 0, 0 } )
        CreateDecimal( New Integer( ) { 0,
 0, 1000000000, 0 } )
        CreateDecimal( New Integer( ) { 0,
 0, 0, 1000000000 } )
        CreateDecimal( New Integer( ) { -1,
 -1, -1, 0 } )
        CreateDecimal( New Integer( ) { -1,
 -1, -1, &H80000000 } )
        CreateDecimal( New Integer( ) { -1,
 0, 0, &H100000 } )
        CreateDecimal( New Integer( ) { -1,
 0, 0, &H1C0000 } )
        CreateDecimal( New Integer( ) { -1,
 0, 0, &H1D0000 } )
        CreateDecimal( New Integer( ) { -1,
 0, 0, &H1C0001 } )
        CreateDecimal( New Integer( ) _
            { &HF0000, &HF0000, &HF0000, &HF0000 } )
    End Sub 
End Module 

' This example of the Decimal( Integer( ) ) constructor
' generates the following output.
' 
' Constructor                                               Value or
 Exception
' -----------                                               ------------------
' Decimal( { &H0, &H0, &H0, &H0 } )                
                          0
' Decimal( { &H0, &H0, &H0 } )                         
      ArgumentException
' Decimal( { &H0, &H0, &H0, &H0, &H0 } )       
              ArgumentException
' Decimal( { &H3B9ACA00, &H0, &H0, &H0 } )         
                 1000000000
' Decimal( { &H0, &H3B9ACA00, &H0, &H0 } )         
        4294967296000000000
' Decimal( { &H0, &H0, &H3B9ACA00, &H0 } )       18446744073709551616000000000
' Decimal( { &H0, &H0, &H0, &H3B9ACA00 } )         
          ArgumentException
' Decimal( { &HFFFFFFFF, &HFFFFFFFF, &HFFFFFFFF, &H0
 } )
'                                                79228162514264337593543950335
' Decimal( { &HFFFFFFFF, &HFFFFFFFF, &HFFFFFFFF, &H80000000
 } )
'                                               -79228162514264337593543950335
' Decimal( { &HFFFFFFFF, &H0, &H0, &H100000 } )    
         0.0000004294967295
' Decimal( { &HFFFFFFFF, &H0, &H0, &H1C0000 } ) 0.0000000000000000004294967295
' Decimal( { &HFFFFFFFF, &H0, &H0, &H1D0000 } )    
          ArgumentException
' Decimal( { &HFFFFFFFF, &H0, &H0, &H1C0001 } )    
          ArgumentException
' Decimal( { &HF0000, &HF0000, &HF0000, &HF0000 } )
'                                                  18133887298.441562272235520
// Example of the decimal( int[ ] ) constructor.
using System;

class DecimalCtorIArrDemo
{
    // Get the exception type name; remove the namespace prefix.
    public static string
 GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring( 
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Create a decimal object and display its value.
    public static void CreateDecimal(
 int[ ] bits )
    {
        // Format the constructor for display.
        string ctor = String.Format( 
            "decimal( {{ 0x{0:X}", bits[ 0 ] );
        string valOrExc;
        
        for( int index = 1; index < bits.Length;
 index++ )
            ctor += String.Format( ", 0x{0:X}", bits[ index ] );
        ctor += " } )";

        try
        {
            // Construct the decimal value.
            decimal decimalNum = new decimal( bits );

            // Format the decimal value for display.
            valOrExc = decimalNum.ToString( );
        }
        catch( Exception ex )
        {
            // Save the exception type if an exception was thrown.
            valOrExc = GetExceptionType( ex );
        }

        // Display the constructor and decimal value or exception.
        int ctorLen = 76 - valOrExc.Length;

        // Display the data on one line if it will fit.
        if( ctorLen > ctor.Length )
            Console.WriteLine( "{0}{1}", ctor.PadRight( ctorLen ), 
                valOrExc );

        // Otherwise, display the data on two lines.
        else
        {
            Console.WriteLine( "{0}", ctor );
            Console.WriteLine( "{0,76}", valOrExc );
        }
    }
    
    public static void Main(
 )
    {
        Console.WriteLine( 
            "This example of the decimal( int[ ] ) constructor
 " +
            "\ngenerates the following output.\n" );
        Console.WriteLine( "{0,-38}{1,38}", "Constructor", 
            "Value or Exception" );
        Console.WriteLine( "{0,-38}{1,38}", "-----------", 
            "------------------" );

        // Construct decimal objects from integer arrays.
        CreateDecimal( new int[ ] { 0, 0, 0,
 0 } );
        CreateDecimal( new int[ ] { 0, 0, 0
 } );
        CreateDecimal( new int[ ] { 0, 0, 0,
 0, 0 } );
        CreateDecimal( new int[ ] { 1000000000,
 0, 0, 0 } );
        CreateDecimal( new int[ ] { 0, 1000000000,
 0, 0 } );
        CreateDecimal( new int[ ] { 0, 0, 1000000000,
 0 } );
        CreateDecimal( new int[ ] { 0, 0, 0,
 1000000000 } );
        CreateDecimal( new int[ ] { -1, -1,
 -1, 0 } );
        CreateDecimal( new int[ ] 
            { -1, -1, -1, unchecked( (int)0x80000000 ) } );
        CreateDecimal( new int[ ] { -1, 0,
 0, 0x100000 } );
        CreateDecimal( new int[ ] { -1, 0,
 0, 0x1C0000 } );
        CreateDecimal( new int[ ] { -1, 0,
 0, 0x1D0000 } );
        CreateDecimal( new int[ ] { -1, 0,
 0, 0x1C0001 } );
        CreateDecimal( new int[ ] 
            { 0xF0000, 0xF0000, 0xF0000, 0xF0000 } );
    }
}

/*
This example of the decimal( int[ ] ) constructor
generates the following output.

Constructor                                               Value or Exception
-----------                                               ------------------
decimal( { 0x0, 0x0, 0x0, 0x0 } )                                          0
decimal( { 0x0, 0x0, 0x0 } )                               ArgumentException
decimal( { 0x0, 0x0, 0x0, 0x0, 0x0 } )                     ArgumentException
decimal( { 0x3B9ACA00, 0x0, 0x0, 0x0 } )                          1000000000
decimal( { 0x0, 0x3B9ACA00, 0x0, 0x0 } )                 4294967296000000000
decimal( { 0x0, 0x0, 0x3B9ACA00, 0x0 } )       18446744073709551616000000000
decimal( { 0x0, 0x0, 0x0, 0x3B9ACA00 } )                   ArgumentException
decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0 } )
                                               79228162514264337593543950335
decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x80000000 } )
                                              -79228162514264337593543950335
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x100000 } )             0.0000004294967295
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0000 } ) 0.0000000000000000004294967295
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1D0000 } )              ArgumentException
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0001 } )              ArgumentException
decimal( { 0xF0000, 0xF0000, 0xF0000, 0xF0000 } )
                                                 18133887298.441562272235520
*/
// Example of the Decimal( int __gc [ ] ) constructor.
using namespace System;

// Get the exception type name; remove the namespace prefix.
String^ GetExceptionType( Exception^ ex )
{
   String^ exceptionType = ex->GetType()->ToString();
   return exceptionType->Substring( exceptionType->LastIndexOf(
 '.' ) + 1 );
}


// Create a Decimal object and display its value.
void CreateDecimal( array<int>^bits )
{
   
   // Format the constructor for display.
   String^ ctor = String::Format( "Decimal( {{ 0x{0:X}", bits[ 0 ] );
   String^ valOrExc;
   for ( int index = 1; index < bits->Length;
 index++ )
      ctor = String::Concat( ctor, String::Format( ", 0x{0:X}", bits[ index
 ] ) );
   ctor = String::Concat( ctor, " } )" );
   try
   {
      
      // Construct the Decimal value.
      Decimal decimalNum = Decimal(bits);
      
      // Format the Decimal value for display.
      valOrExc = decimalNum.ToString();
   }
   catch ( Exception^ ex ) 
   {
      
      // Save the exception type if an exception was thrown.
      valOrExc = GetExceptionType( ex );
   }

   
   // Display the constructor and Decimal value or exception.
   int ctorLen = 76 - valOrExc->Length;
   
   // Display the data on one line if it will fit.
   if ( ctorLen > ctor->Length )
      Console::WriteLine( "{0}{1}", ctor->PadRight( ctorLen ), valOrExc
 );
   // Otherwise, display the data on two lines.
   else
   {
      Console::WriteLine( "{0}", ctor );
      Console::WriteLine( "{0,76}", valOrExc );
   }
}

int main()
{
   Console::WriteLine( "This example of the Decimal( int
 __gc [ ] ) "
   "constructor \ngenerates the following output.\n" );
   Console::WriteLine( "{0,-38}{1,38}", "Constructor", "Value
 or Exception" );
   Console::WriteLine( "{0,-38}{1,38}", "-----------", "------------------"
 );
   
   // Construct Decimal objects from integer arrays.
   array<Int32>^zero = {0,0,0,0};
   CreateDecimal( zero );
   array<Int32>^arrayShort = {0,0,0};
   CreateDecimal( arrayShort );
   array<Int32>^arrayLong = {0,0,0,0,0};
   CreateDecimal( arrayLong );
   array<Int32>^word0Data = {1000000000,0,0,0};
   CreateDecimal( word0Data );
   array<Int32>^word1Data = {0,1000000000,0,0};
   CreateDecimal( word1Data );
   array<Int32>^word2Data = {0,0,1000000000,0};
   CreateDecimal( word2Data );
   array<Int32>^word3Data = {0,0,0,1000000000};
   CreateDecimal( word3Data );
   array<Int32>^decMax = { -1,-1,-1,0};
   CreateDecimal( decMax );
   array<Int32>^decMin = { -1,-1,-1,0x80000000};
   CreateDecimal( decMin );
   array<Int32>^fracDig16 = { -1,0,0,0x100000};
   CreateDecimal( fracDig16 );
   array<Int32>^fracDig28 = { -1,0,0,0x1C0000};
   CreateDecimal( fracDig28 );
   array<Int32>^fracDig29 = { -1,0,0,0x1D0000};
   CreateDecimal( fracDig29 );
   array<Int32>^reserved = { -1,0,0,0x1C0001};
   CreateDecimal( reserved );
   array<Int32>^Same4Words = {0xF0000,0xF0000,0xF0000,0xF0000};
   CreateDecimal( Same4Words );
}

/*
This example of the Decimal( int __gc [ ] ) constructor
generates the following output.

Constructor                                               Value or Exception
-----------                                               ------------------
Decimal( { 0x0, 0x0, 0x0, 0x0 } )                                          0
Decimal( { 0x0, 0x0, 0x0 } )                               ArgumentException
Decimal( { 0x0, 0x0, 0x0, 0x0, 0x0 } )                     ArgumentException
Decimal( { 0x3B9ACA00, 0x0, 0x0, 0x0 } )                          1000000000
Decimal( { 0x0, 0x3B9ACA00, 0x0, 0x0 } )                 4294967296000000000
Decimal( { 0x0, 0x0, 0x3B9ACA00, 0x0 } )       18446744073709551616000000000
Decimal( { 0x0, 0x0, 0x0, 0x3B9ACA00 } )                   ArgumentException
Decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0 } )
                                               79228162514264337593543950335
Decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x80000000 } )
                                              -79228162514264337593543950335
Decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x100000 } )             0.0000004294967295
Decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0000 } ) 0.0000000000000000004294967295
Decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1D0000 } )              ArgumentException
Decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0001 } )              ArgumentException
Decimal( { 0xF0000, 0xF0000, 0xF0000, 0xF0000 } )
                                                 18133887298.441562272235520
*/
// Example of the decimal( int[ ] ) constructor.
import System.* ;

class DecimalCtorIArrDemo
{
    // Get the exception type name; remove the namespace prefix.
    public static String GetExceptionType(System.Exception
 ex)
    {
        String exceptionType = ex.GetType().ToString();
        return exceptionType.Substring((exceptionType.LastIndexOf('.')
 + 1));
    } //GetExceptionType

    // Create a decimal object and display its value.
    public static void CreateDecimal(int[]
 bits)
    {
        // Format the constructor for display.
        String ctor = String.Format("decimal( {{ 0x{0:X}", bits.get_Item(0));
        String valOrExc;

        for (int index = 1; index < bits.length;
 index++) {
            ctor += String.Format(", 0x{0:X}", bits.get_Item(index));
        }

        ctor += " } )";
        try {
            // Construct the decimal value.
            System.Decimal decimalNum = new System.Decimal(bits);

            // Format the decimal value for display.
            valOrExc = decimalNum.ToString();
        }
        catch (System.Exception ex)    {
            // Save the exception type if an exception was thrown.
            valOrExc = System.Convert.ToString(GetExceptionType(ex));
        }

        // Display the constructor and decimal value or exception.
        int ctorLen = 76 - valOrExc.get_Length();

        // Display the data on one line if it will fit.
        if (ctorLen > ctor.get_Length()) {
            Console.WriteLine("{0}{1}", ctor.PadRight(ctorLen), valOrExc);
        }
        // Otherwise, display the data on two lines.
        else {
            Console.WriteLine("{0}", ctor);
            Console.WriteLine("{0,76}", valOrExc);
        }
    } //CreateDecimal

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of the decimal( int[
 ] ) constructor " 
            + "\ngenerates the following output.\n"));
        Console.WriteLine("{0,-38}{1,38}", "Constructor", "Value
 or Exception");
        Console.WriteLine("{0,-38}{1,38}", "-----------", "------------------");

        // Construct decimal objects from integer arrays.
        CreateDecimal(new int[] { 0, 0, 0,
 0 });
        CreateDecimal(new int[] { 0, 0, 0 });
        CreateDecimal(new int[] { 0, 0, 0,
 0, 0 });
        CreateDecimal(new int[] { 1000000000,
 0, 0, 0 });
        CreateDecimal(new int[] { 0, 1000000000,
 0, 0 });
        CreateDecimal(new int[] { 0, 0, 1000000000,
 0 });
        CreateDecimal(new int[] { 0, 0, 0,
 1000000000 });
        CreateDecimal(new int[] { -1, -1, -1,
 0 });
        CreateDecimal(new int[] { -1, -1, -1,
 (int)(0x80000000) });
        CreateDecimal(new int[] { -1, 0, 0,
 0x100000 });
        CreateDecimal(new int[] { -1, 0, 0,
 0x1C0000 });
        CreateDecimal(new int[] { -1, 0, 0,
 0x1D0000 });
        CreateDecimal(new int[] { -1, 0, 0,
 0x1C0001 });
        CreateDecimal(new int[] { 0xF0000,
 0xF0000, 0xF0000, 0xF0000 });
    } //main
} //DecimalCtorIArrDemo

/*
This example of the decimal( int[ ] ) constructor
generates the following output.

Constructor                                               Value or Exception
-----------                                               ------------------
decimal( { 0x0, 0x0, 0x0, 0x0 } )                                          0
decimal( { 0x0, 0x0, 0x0 } )                               ArgumentException
decimal( { 0x0, 0x0, 0x0, 0x0, 0x0 } )                     ArgumentException
decimal( { 0x3B9ACA00, 0x0, 0x0, 0x0 } )                          1000000000
decimal( { 0x0, 0x3B9ACA00, 0x0, 0x0 } )                 4294967296000000000
decimal( { 0x0, 0x0, 0x3B9ACA00, 0x0 } )       18446744073709551616000000000
decimal( { 0x0, 0x0, 0x0, 0x3B9ACA00 } )                   ArgumentException
decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0 } )
                                               79228162514264337593543950335
decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x80000000 } )
                                              -79228162514264337593543950335
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x100000 } )             0.0000004294967295
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0000 } ) 0.0000000000000000004294967295
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1D0000 } )              ArgumentException
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0001 } )              ArgumentException
decimal( { 0xF0000, 0xF0000, 0xF0000, 0xF0000 } )
                                                 18133887298.441562272235520
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Decimal コンストラクタ (UInt32)

Decimal の新しいインスタンスを作成して、その値を、指定した 32 ビット符号なし整数に設定します。

このコンストラクタは、CLS に準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Sub New ( _
    value As UInteger _
)
Dim value As UInteger

Dim instance As New Decimal(value)
[CLSCompliantAttribute(false)] 
public Decimal (
    uint value
)
[CLSCompliantAttribute(false)] 
public:
Decimal (
    unsigned int value
)
/** @attribute CLSCompliantAttribute(false) */ 
public Decimal (
    UInt32 value
)
CLSCompliantAttribute(false) 
public function Decimal (
    value : uint
)

パラメータ

value

Decimal として表す値。

使用例使用例

Decimal 構造体を UInt32 値で初期化するコンストラクタのオーバーロードを使用して、複数の Decimal 数値を作成するコード例を次に示します。

' Example of the Decimal( UInt32 ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module DecimalCtorUIDemo

    ' Create a Decimal object and display its value.
    Sub CreateDecimal( value As UInt32, valToStr
 As String )

        Dim decimalNum As New
 Decimal( value )

        ' Format the constructor for display.
        Dim ctor As String
 = _
            String.Format( "Decimal( {0} )",
 valToStr )

        ' Display the constructor and its value.
        Console.WriteLine( "{0,-33}{1,16}", ctor,
 decimalNum )
    End Sub
    
    Sub Main( )

        Console.WriteLine( _
            "This example of the Decimal( UInt32 ) constructor
 " & _
            vbCrLf & "generates the following output."
 & vbCrLf )
        Console.WriteLine( "{0,-33}{1,16}", "Constructor",
 "Value" )
        Console.WriteLine( "{0,-33}{1,16}", "-----------",
 "-----" )

        ' Construct Decimal objects from UInt32 values.
        ' UInt32.MinValue and UInt32.MaxValue are not defined in VB.
        CreateDecimal( Convert.ToUInt32( 0 ), """UInt32.MinValue"""
 )
        CreateDecimal( Convert.ToUInt32( 4294967295 ), _
            """UInt32.MaxValue"""
 )
        CreateDecimal( Convert.ToUInt32( Integer.MaxValue ), _
            "Integer.MaxValue" )              
        CreateDecimal( Convert.ToUInt32( 999999999 ), "999999999"
 ) 
        CreateDecimal( Convert.ToUInt32( &H40000000 ), "&H40000000"
 ) 
        CreateDecimal( Convert.ToUInt32( &HC0000000L ), "&HC0000000"
 )
    End Sub 
End Module 

' This example of the Decimal( UInt32 ) constructor
' generates the following output.
' 
' Constructor                                 Value
' -----------                                 -----
' Decimal( "UInt32.MinValue" )                    0
' Decimal( "UInt32.MaxValue" )           4294967295
' Decimal( Integer.MaxValue )            2147483647
' Decimal( 999999999 )                    999999999
' Decimal( &H40000000 )                  1073741824
' Decimal( &HC0000000 )                  3221225472
// Example of the decimal( uint ) constructor.
using System;

class DecimalCtorUIDemo
{
    // Create a decimal object and display its value.
    public static void CreateDecimal(
 uint value, string valToStr )
    {
        decimal decimalNum = new decimal( value );

        // Format the constructor for display.
        string ctor = String.Format( "decimal( {0} )",
 valToStr );

        // Display the constructor and its value.
        Console.WriteLine( "{0,-33}{1,16}", ctor, decimalNum );
    }
    
    public static void Main(
 )
    {
        Console.WriteLine( "This example of the decimal( uint ) " +
            "constructor \ngenerates the following output.\n" );
        Console.WriteLine( "{0,-33}{1,16}", "Constructor", "Value"
 );
        Console.WriteLine( "{0,-33}{1,16}", "-----------", "-----"
 );

        // Construct decimal objects from uint values.
        CreateDecimal( uint.MinValue, "uint.MinValue" );
        CreateDecimal( uint.MaxValue, "uint.MaxValue" );
        CreateDecimal( (uint)int.MaxValue, "(uint)int.MaxValue"
 );
        CreateDecimal( 999999999U, "999999999U" );
        CreateDecimal( 0x40000000U, "0x40000000U" );
        CreateDecimal( 0xC0000000, "0xC0000000" );
    }
}

/*
This example of the decimal( uint ) constructor
generates the following output.

Constructor                                 Value
-----------                                 -----
decimal( uint.MinValue )                        0
decimal( uint.MaxValue )               4294967295
decimal( (uint)int.MaxValue )          2147483647
decimal( 999999999U )                   999999999
decimal( 0x40000000U )                 1073741824
decimal( 0xC0000000 )                  3221225472
*/
// Example of the Decimal( unsigned int ) constructor.
using namespace System;

// Create a Decimal object and display its value.
void CreateDecimal( unsigned int value, String^
 valToStr )
{
   Decimal decimalNum = Decimal(value);
   
   // Format the constructor for display.
   String^ ctor = String::Format( "Decimal( {0} )", valToStr );
   
   // Display the constructor and its value.
   Console::WriteLine( "{0,-30}{1,16}", ctor, decimalNum );
}

int main()
{
   Console::WriteLine( "This example of the Decimal( unsigned "
   "int ) constructor \ngenerates the following output.\n"
 );
   Console::WriteLine( "{0,-30}{1,16}", "Constructor", "Value"
 );
   Console::WriteLine( "{0,-30}{1,16}", "-----------", "-----"
 );
   
   // Construct Decimal objects from unsigned int values.
   CreateDecimal( UInt32::MinValue, "UInt32::MinValue" );
   CreateDecimal( UInt32::MaxValue, "UInt32::MaxValue" );
   CreateDecimal( Int32::MaxValue, "Int32::MaxValue" );
   CreateDecimal( 999999999, "999999999" );
   CreateDecimal( 0x40000000, "0x40000000" );
   CreateDecimal( 0xC0000000, "0xC0000000" );
}

/*
This example of the Decimal( unsigned int ) constructor
generates the following output.

Constructor                              Value
-----------                              -----
Decimal( UInt32::MinValue )                  0
Decimal( UInt32::MaxValue )         4294967295
Decimal( Int32::MaxValue )          2147483647
Decimal( 999999999 )                 999999999
Decimal( 0x40000000 )               1073741824
Decimal( 0xC0000000 )               3221225472
*/
// Example of the decimal( uint ) constructor.
import System.* ;

class DecimalCtorUIDemo
{   
    // Create a decimal object and display its value.
    public static void CreateDecimal(UInt32
 value, String valToStr) 
    {
        System.Decimal decimalNum =  new System.Decimal(value);
        
        // Format the constructor for display.
        String ctor = String.Format("decimal( {0} )", valToStr);
        
        // Display the constructor and its value.
        Console.WriteLine("{0,-33}{1,16}", ctor, decimalNum);
    } //CreateDecimal

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of the decimal( uint ) "
            + "constructor \ngenerates the following output.\n"));
        Console.WriteLine("{0,-33}{1,16}", "Constructor", "Value");
        Console.WriteLine("{0,-33}{1,16}", "-----------", "-----");
        
        // Construct decimal objects from uint values.
        CreateDecimal(Convert.ToUInt32(UInt64.MinValue) , "uint.MinValue");
        CreateDecimal( UInt32.MaxValue, "uint.MaxValue");
        CreateDecimal(((UInt32) Int32.MaxValue), "(uint)int.MaxValue");
        CreateDecimal(Convert.ToUInt32(999999999), "999999999U");
        CreateDecimal(Convert.ToUInt32(0x40000000), "0x40000000U");
        CreateDecimal((UInt32)(0xC0000000), "0xC0000000");
        
    } //main
} //DecimalCtorUIDemo

/*
This example of the decimal( uint ) constructor
generates the following output.

Constructor                                 Value
-----------                                 -----
decimal( uint.MinValue )                        0
decimal( uint.MaxValue )               4294967295
decimal( (uint)int.MaxValue )          2147483647
decimal( 999999999U )                   999999999
decimal( 0x40000000U )                 1073741824
decimal( 0xC0000000 )                  3221225472
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Decimal フィールド


パブリック フィールドパブリック フィールド

  名前 説明
パブリック フィールド Zero 数値 0 を表します。
参照参照

関連項目

Decimal 構造体
System 名前空間
SByte
Int16
Int32
Int64
Byte 構造体
UInt16
UInt32
UInt64
Single
Double
Char 構造体

Decimal メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド Add 指定した 2 つの Decimal 値を加算します。
パブリック メソッド Ceiling 指定した 10 進数以上の数のうち、最小の整数を返します。
パブリック メソッド Compare 指定した 2 つの Decimal 値を比較します。
パブリック メソッド CompareTo オーバーロードされます。 指定したオブジェクトまたは Decimal とこのインスタンスを比較し、これらの相対値を示す値を返します。
パブリック メソッド Divide 指定した 2 つの Decimal 値を除算します。
パブリック メソッド Equals オーバーロードされます。 Decimal の 2 つのインスタンスが同じ値を表しているかどうかを示す値を返します。
パブリック メソッド Floor 指定した Decimal 数を、負の無限大方向の近似整数に丸めます。
パブリック メソッド FromOACurrency OLE オートメーション通貨値を格納している指定した 64 ビット符号付き整数を、それと等価の Decimal 値に変換します。
パブリック メソッド GetBits 指定した Decimal のインスタンスの値を、それと等価のバイナリ形式に変換します。
パブリック メソッド GetHashCode オーバーライドされます。 このインスタンスのハッシュ コードを返します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド GetTypeCode Decimal 値型の TypeCode を返します。
パブリック メソッド Multiply 指定した 2 つの Decimal 値を乗算します。
パブリック メソッド Negate 指定した Decimal 値に -1 を乗算した結果を返します。
パブリック メソッド op_Addition 指定した 2 つの Decimal 値を加算します。
パブリック メソッド op_Decrement Decimal オペランドを 1 だけデクリメントします。
パブリック メソッド op_Division 指定した 2 つの Decimal 値を除算します。
パブリック メソッド op_Equality Decimal の 2 つのインスタンスが等しいかどうかを示す値を返します。
パブリック メソッド op_Explicit オーバーロードされます。 Decimal オブジェクトの値を別の型に変換します。
パブリック メソッド op_GreaterThan 指定した Decimal が、指定したもう 1 つの Decimal より大きいかどうかを示す値を返します。
パブリック メソッド op_GreaterThanOrEqual 指定した Decimal が、指定したもう 1 つの Decimal 以上かどうかを示す値を返します。
パブリック メソッド op_Implicit オーバーロードされます。 型の値を Decimal 値に変換します。
パブリック メソッド op_Increment Decimal オペランドを 1 だけインクリメントします。
パブリック メソッド op_Inequality Decimal の 2 つのインスタンスが等しくないかどうかを示す値を返します。
パブリック メソッド op_LessThan 指定した Decimal が、指定したもう 1 つの Decimal より小さいかどうかを示す値を返します。
パブリック メソッド op_LessThanOrEqual 指定した Decimal が、指定したもう 1 つの Decimal 以下であるかどうかを示す値を返します。
パブリック メソッド op_Modulus 指定した 2 つの Decimal 値を除算した結果の剰余を返します。
パブリック メソッド op_Multiply 指定した 2 つの Decimal 値を乗算します。
パブリック メソッド op_Subtraction 指定した 2 つの Decimal 値を減算します。
パブリック メソッド op_UnaryNegation 指定した Decimal オペランドの値を無効にします。
パブリック メソッド op_UnaryPlus Decimal オペランドの値 (オペランドの符号は不変) を返します。
パブリック メソッド Parse オーバーロードされます。 数値の String 形式をそれと等価な Decimal に変換します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド Remainder 2 つの Decimal 値の除算後の剰余を計算します。
パブリック メソッド Round オーバーロードされます。 値を最も近い整数または指定した小数点数に丸めます。
パブリック メソッド Subtract 指定した Decimal 値から、指定したもう 1 つの値を減算します。
パブリック メソッド ToByte 指定した Decimal の値を、等価の 8 ビット符号なし整数に変換します。
パブリック メソッド ToDouble 指定した Decimal の値を、それと等価の倍精度浮動小数点数に変換します。
パブリック メソッド ToInt16 指定した Decimal の値を、等価の 16 ビット符号付き整数に変換します。
パブリック メソッド ToInt32 指定した Decimal の値を、等価の 32 ビット符号付き整数に変換します。
パブリック メソッド ToInt64 指定した Decimal の値を、等価の 64 ビット符号付き整数に変換します。
パブリック メソッド ToOACurrency 指定した Decimal 値を、64 ビット符号付き整数に格納されるそれと等価の OLE オートメーション通貨値に変換します。
パブリック メソッド ToSByte 指定した Decimal の値を、等価の 8 ビット符号付き整数に変換します。
パブリック メソッド ToSingle 指定した Decimal の値を、それと等価の単精度浮動小数点数に変換します。
パブリック メソッド ToString オーバーロードされます。 オーバーライドされます。 対象のインスタンスの数値を等価の String 形式に変換します。
パブリック メソッド ToUInt16 指定した Decimal の値を、等価の 16 ビット符号なし整数に変換します。
パブリック メソッド ToUInt32 指定した Decimal の値を、等価の 32 ビット符号なし整数に変換します。
パブリック メソッド ToUInt64 指定した Decimal の値を、等価の 64 ビット符号なし整数に変換します。
パブリック メソッド Truncate 指定した Decimal の整数の桁を返します。小数の桁は破棄されます。
パブリック メソッド TryParse オーバーロードされます。 数値の String 形式をそれと等価な Decimal に変換します。戻り値は、変換が成功したか失敗したかを示します。
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.IConvertible.ToBoolean この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。
インターフェイスの明示的な実装 System.IConvertible.ToByte Decimal を 8 ビット符号なし整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToChar この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。
インターフェイスの明示的な実装 System.IConvertible.ToDateTime この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。
インターフェイスの明示的な実装 System.IConvertible.ToDecimal Decimal のこのインスタンスを返します。
インターフェイスの明示的な実装 System.IConvertible.ToDouble Decimal のこのインスタンスを倍精度浮動小数点数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToInt16 Decimal を 16 ビット符号付き整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToInt32 Decimal のこのインスタンスを 32 ビット符号付き整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToInt64 Decimal のこのインスタンスを 64 ビット符号付き整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToSByte 既定の書式を使用して、Decimal を SByte に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToSingle Decimal のこのインスタンスを単精度浮動小数点数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToType Decimal のこのインスタンスの値と等価の値を持つ、指定した Type のオブジェクトを返します。
インターフェイスの明示的な実装 System.IConvertible.ToUInt16 Decimal のこのインスタンスを 16 ビット符号なし整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToUInt32 Decimal のこのインスタンスを 32 ビット符号なし整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToUInt64 Decimal のこのインスタンスを 64 ビット符号なし整数に変換します。
参照参照

関連項目

Decimal 構造体
System 名前空間
SByte
Int16
Int32
Int64
Byte 構造体
UInt16
UInt32
UInt64
Single
Double
Char 構造体

Decimal メンバ

10 進数を表します。

Decimal データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
パブリック フィールドパブリック フィールド
  名前 説明
パブリック フィールド Zero 数値 0 を表します。
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Add 指定した 2 つの Decimal 値を加算します。
パブリック メソッド Ceiling 指定した 10 進数以上の数のうち、最小の整数を返します。
パブリック メソッド Compare 指定した 2 つの Decimal 値を比較します。
パブリック メソッド CompareTo オーバーロードされます。 指定したオブジェクトまたは Decimal とこのインスタンスを比較し、これらの相対値を示す値を返します。
パブリック メソッド Divide 指定した 2 つの Decimal 値を除算します。
パブリック メソッド Equals オーバーロードされます。 Decimal の 2 つのインスタンスが同じ値を表しているかどうかを示す値を返します。
パブリック メソッド Floor 指定した Decimal 数を、負の無限大方向の近似整数に丸めます。
パブリック メソッド FromOACurrency OLE オートメーション通貨値を格納している指定した 64 ビット符号付き整数を、それと等価の Decimal 値に変換します。
パブリック メソッド GetBits 指定した Decimal のインスタンスの値を、それと等価のバイナリ形式に変換します。
パブリック メソッド GetHashCode オーバーライドされます。 このインスタンスのハッシュ コードを返します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド GetTypeCode Decimal 値型の TypeCode を返します。
パブリック メソッド Multiply 指定した 2 つの Decimal 値を乗算します。
パブリック メソッド Negate 指定した Decimal 値に -1 を乗算した結果を返します。
パブリック メソッド op_Addition 指定した 2 つの Decimal 値を加算します。
パブリック メソッド op_Decrement Decimal オペランドを 1 だけデクリメントします。
パブリック メソッド op_Division 指定した 2 つの Decimal 値を除算します。
パブリック メソッド op_Equality Decimal の 2 つのインスタンスが等しいかどうかを示す値を返します。
パブリック メソッド op_Explicit オーバーロードされます。 Decimal オブジェクトの値を別の型に変換します。
パブリック メソッド op_GreaterThan 指定した Decimal が、指定したもう 1 つの Decimal より大きいかどうかを示す値を返します。
パブリック メソッド op_GreaterThanOrEqual 指定した Decimal が、指定したもう 1 つの Decimal 以上かどうかを示す値を返します。
パブリック メソッド op_Implicit オーバーロードされます。 型の値を Decimal 値に変換します。
パブリック メソッド op_Increment Decimal オペランドを 1 だけインクリメントします。
パブリック メソッド op_Inequality Decimal の 2 つのインスタンスが等しくないかどうかを示す値を返します。
パブリック メソッド op_LessThan 指定した Decimal が、指定したもう 1 つの Decimal より小さいかどうかを示す値を返します。
パブリック メソッド op_LessThanOrEqual 指定した Decimal が、指定したもう 1 つの Decimal 以下であるかどうかを示す値を返します。
パブリック メソッド op_Modulus 指定した 2 つの Decimal 値を除算した結果の剰余を返します。
パブリック メソッド op_Multiply 指定した 2 つの Decimal 値を乗算します。
パブリック メソッド op_Subtraction 指定した 2 つの Decimal 値を減算します。
パブリック メソッド op_UnaryNegation 指定した Decimal オペランドの値を無効にします。
パブリック メソッド op_UnaryPlus Decimal オペランドの値 (オペランドの符号は不変) を返します。
パブリック メソッド Parse オーバーロードされます。 数値の String 形式をそれと等価な Decimal に変換します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド Remainder 2 つの Decimal 値の除算後の剰余を計算します。
パブリック メソッド Round オーバーロードされます。 値を最も近い整数または指定した小数点数に丸めます。
パブリック メソッド Subtract 指定した Decimal 値から、指定したもう 1 つの値を減算します。
パブリック メソッド ToByte 指定した Decimal の値を、等価の 8 ビット符号なし整数に変換します。
パブリック メソッド ToDouble 指定した Decimal の値を、それと等価の倍精度浮動小数点数に変換します。
パブリック メソッド ToInt16 指定した Decimal の値を、等価の 16 ビット符号付き整数に変換します。
パブリック メソッド ToInt32 指定した Decimal の値を、等価の 32 ビット符号付き整数に変換します。
パブリック メソッド ToInt64 指定した Decimal の値を、等価の 64 ビット符号付き整数に変換します。
パブリック メソッド ToOACurrency 指定した Decimal 値を、64 ビット符号付き整数に格納されるそれと等価の OLE オートメーション通貨値に変換します。
パブリック メソッド ToSByte 指定した Decimal の値を、等価の 8 ビット符号付き整数に変換します。
パブリック メソッド ToSingle 指定した Decimal の値を、それと等価の単精度浮動小数点数に変換します。
パブリック メソッド ToString オーバーロードされます。 オーバーライドされます。 対象のインスタンスの数値を等価の String 形式に変換します。
パブリック メソッド ToUInt16 指定した Decimal の値を、等価の 16 ビット符号なし整数に変換します。
パブリック メソッド ToUInt32 指定した Decimal の値を、等価の 32 ビット符号なし整数に変換します。
パブリック メソッド ToUInt64 指定した Decimal の値を、等価の 64 ビット符号なし整数に変換します。
パブリック メソッド Truncate 指定した Decimal の整数の桁を返します。小数の桁は破棄されます。
パブリック メソッド TryParse オーバーロードされます。 数値の String 形式をそれと等価な Decimal に変換します。戻り値は、変換が成功したか失敗したかを示します。
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.IConvertible.ToBoolean この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。
インターフェイスの明示的な実装 System.IConvertible.ToByte Decimal を 8 ビット符号なし整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToChar この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。
インターフェイスの明示的な実装 System.IConvertible.ToDateTime この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。
インターフェイスの明示的な実装 System.IConvertible.ToDecimal Decimal のこのインスタンスを返します。
インターフェイスの明示的な実装 System.IConvertible.ToDouble Decimal のこのインスタンスを倍精度浮動小数点数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToInt16 Decimal を 16 ビット符号付き整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToInt32 Decimal のこのインスタンスを 32 ビット符号付き整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToInt64 Decimal のこのインスタンスを 64 ビット符号付き整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToSByte 既定の書式を使用して、Decimal を SByte に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToSingle Decimal のこのインスタンスを単精度浮動小数点数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToType Decimal のこのインスタンスの値と等価の値を持つ、指定した Type のオブジェクトを返します。
インターフェイスの明示的な実装 System.IConvertible.ToUInt16 Decimal のこのインスタンスを 16 ビット符号なし整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToUInt32 Decimal のこのインスタンスを 32 ビット符号なし整数に変換します。
インターフェイスの明示的な実装 System.IConvertible.ToUInt64 Decimal のこのインスタンスを 64 ビット符号なし整数に変換します。
参照参照

関連項目

Decimal 構造体
System 名前空間
SByte
Int16
Int32
Int64
Byte 構造体
UInt16
UInt32
UInt64
Single
Double
Char 構造体

Decimal 構造体

10 進数を表します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Structure Decimal
    Implements IFormattable, IComparable, IConvertible, IComparable(Of
 Decimal), _
    IEquatable(Of Decimal)
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public struct Decimal : IFormattable, IComparable, IConvertible,
 
    IComparable<decimal>, IEquatable<decimal>
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public value class Decimal : IFormattable,
 IComparable, IConvertible, 
    IComparable<Decimal>, IEquatable<Decimal>
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class Decimal extends ValueType
 implements IFormattable, IComparable, 
    IConvertible, IComparable<Decimal>, IEquatable<Decimal>
JScript では、構造体を使用できますが、新規に宣言することはできません。
解説解説

Decimal 値型は、正の 79,228,162,514,264,337,593,543,950,335 から負の 79,228,162,514,264,337,593,543,950,335 までの範囲の 10 進数を表します。Decimal 値型は、多数の有効な整数桁と小数桁を必要とし、丸め誤差を使用しない財務計算に適しています。

10 進数は、符号、値の各桁の範囲が 0 から 9 までの数値、数値の整数部と小数部を分ける浮動小数点の位置を示すスケール ファクタで構成される浮動小数点値です。

Decimal 値のバイナリ表現は、1 ビットの符号、96 ビットの整数、および 96 ビットの整数値を除算し、小数部を指定するために使用するスケール ファクタで構成されます。スケール ファクタは、暗黙で数値 10 になり、0 から 28 の範囲の指数で累乗されます。したがって、Decimal 値のバイナリ表現は、((-296 ~ 296) / 10(0 ~ 28)) の形式です。-296-1 は MinValue に等しく、296-1 は MaxValue に等しい値です。

スケール ファクタでは、Decimal 数値内の後続のゼロも保持されます。後続のゼロは、算術演算または比較演算では Decimal 数値の値に影響しません。ただし、適切な書式指定文字列を適用すると、後続のゼロを ToString メソッドによって確認できます。

変換に関する考慮事項

この型は、Decimal 値を型 Char、SByte、Int16、Int32、Int64、Byte、UInt16、UInt32、および UInt64 に変換したり、その逆方向に変換したりするメソッドを提供します。他の型から Decimal への変換は、情報が失われたり例外がスローされることのない拡大変換です。

Decimal から他の型への変換は、Decimal 値を 0 方向の近似整数値に丸める縮小変換です。変換結果を変換先の型で表現できない場合は、OverflowException がスローされます。

この型は、Decimal 値を Single および Double に変換したり、その逆方向に変換したりするメソッドを提供します。Decimal から Single または Double への変換は縮小変換であるため、精度が失われる可能性がありますが、変換後の値の大きさに関する情報が失われることはありません。この変換では例外はスローされません。

Single または Double から Decimal への変換では、変換結果を Decimal として表すことができない場合に OverflowException がスローされます。

実装されているインターフェイス

この型は、IComparable、IComparable、IFormattable、IConvertible の各インターフェイスを実装します。この型の明示的な IConvertible インターフェイス メンバの実装の代わりに、Convert クラスを使用します。

使用例使用例

Decimal を使用するコード例を次に示します。

' Keeping my fortune in Decimals to avoid the round-off errors.
Class PiggyBank
    Protected MyFortune As Decimal

    Public Sub AddPenny()
        MyFortune = [Decimal].Add(MyFortune, 0.01D)
    End Sub

    Public ReadOnly Property
 Capacity() As Decimal
        Get
            Return [Decimal].MaxValue
        End Get
    End Property

    Public ReadOnly Property
 Dollars() As Decimal
        Get
            Return [Decimal].Floor(MyFortune)
        End Get
    End Property

    Public ReadOnly Property
 Cents() As Decimal
        Get
            Return [Decimal].Subtract(MyFortune, [Decimal].Floor(MyFortune))
        End Get
    End Property

    Public Overrides Function
 ToString() As String
        Return MyFortune.ToString("C")
 + " in piggy bank"
    End Function
End Class
/// <summary>
/// Keeping my fortune in Decimals to avoid the round-off errors.
/// </summary>
class PiggyBank {
    protected decimal MyFortune;

    public void AddPenny() {
        MyFortune = Decimal.Add(MyFortune, .01m);
    }

    public decimal Capacity {
        get {
            return Decimal.MaxValue;
        }
    }

    public decimal Dollars {
        get {
            return Decimal.Floor(MyFortune);
        }
    }

    public decimal Cents {
        get {
            return Decimal.Subtract(MyFortune, Decimal.Floor(MyFortune));
        }
    }

    public override string ToString() {
        return MyFortune.ToString("C")+" in
 piggy bank";
    }
}
   /// <summary>
   /// Keeping my fortune in Decimals to avoid the round-off errors.
   /// </summary>
   public ref class PiggyBank
   {
   protected:
      Decimal MyFortune;

   public:
      void AddPenny()
      {
         MyFortune = System::Decimal::Add( MyFortune, Decimal(.01) );
      }

      System::Decimal Capacity()
      {
         return MyFortune.MaxValue;
      }

      Decimal Dollars()
      {
         return Decimal::Floor( MyFortune );
      }

      Decimal Cents()
      {
         return Decimal::Subtract( MyFortune, Decimal::Floor(
 MyFortune ) );
      }

      virtual System::String^ ToString() override
      {
         return MyFortune.ToString("C")+" in
 piggy bank";
      }
   };
}
/// <summary>
/// Keeping my fortune in Decimals to avoid the round-off errors.
/// </summary>
class PiggyBank
{
    protected System.Decimal myFortune;

    public void AddPenny()
    {
        myFortune = Decimal.Add(myFortune, System.Convert.ToDecimal(0.01));
    } //AddPenny

    /** @property 
     */
    public System.Decimal get_Capacity()
    {
        return Decimal.MaxValue;
    } //get_Capacity

    /** @property 
     */
    public System.Decimal get_Dollars()
    {
        return Decimal.Floor(myFortune);
    } //get_Dollars

    /** @property 
     */
    public System.Decimal get_Cents()
    {
        return Decimal.Subtract(myFortune, Decimal.Floor(myFortune));
    } //get_Cents

    public String ToString()
    {
        return myFortune.ToString("C") + " in
 piggy bank";
    } //ToString
} //PiggyBank
/// <summary>
/// Keeping my fortune in Decimals to avoid the round-off errors.
/// </summary>
class PiggyBank {
    protected var MyFortune : Decimal;

    public function AddPenny() {
        MyFortune = Decimal.Add(MyFortune, 0.01);
    }

    public function get
 Capacity() : Decimal {
            return Decimal.MaxValue;
    }

    public function get
 Dollars() : Decimal {
        return Decimal.Floor(MyFortune);
    }

    public function get
 Cents() : Decimal {
        return Decimal.Subtract(MyFortune, Decimal.Floor(MyFortune));
    }

    public function ToString() : String {
        return MyFortune.ToString("C")+" in piggy
 bank";
    }
}
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

デシマル(DECIMAL)

デシマル=10進法の単位。1DM(デシマル)=1/100分

decimal

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2020/10/02 08:54 UTC 版)

「C Sharpのデータ型」の記事における「decimal」の解説

C#のdecimal型は128bitの十進浮動小数点数であるが、以下の点で他の浮動小数点数とは大きく異なる。 非数NaN, 負の無限大NegativeInfinity, 正の無限大PositiveInfinityは表現できない。ゼロ除算では、DivideByZeroExceptionをthrowする。 decimal.MaxValueを上回る、あるいはdecimal.MinValueを下回る演算では、OverFlowExceptionをthrowする。 指数部は常に非正数 [-28, 0] を取る。 仮数部は単に96bit符号無し整数として扱われる。 符号未使用指数未使用仮数1 bit7 bits8 bits16 bits96 bitss 0000000 000qqqqq 0000000000000000 cccccccccccccccc ...略... cccccccccccccccc 符号部は 0 ならば正、1 ならば負を表現する。 指数部は 0 〜 28 の値を取り、実際にはその反数の値を表現する。基数は10である。 仮数部は 0 〜 79,228,162,514,264,337,593,543,950,335 の値を表現する。

※この「decimal」の解説は、「C Sharpのデータ型」の解説の一部です。
「decimal」を含む「C Sharpのデータ型」の記事については、「C Sharpのデータ型」の概要を参照ください。

ウィキペディア小見出し辞書の「DECIMAL」の項目はプログラムで機械的に意味や本文を生成しているため、不適切な項目が含まれていることもあります。ご了承くださいませ。 お問い合わせ。


英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DECIMAL」の関連用語

DECIMALのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DECIMALのページの著作権

   
実用日本語表現辞典実用日本語表現辞典
Copyright © 2026実用日本語表現辞典 All Rights Reserved.
デジタル大辞泉デジタル大辞泉
(C)Shogakukan Inc.
株式会社 小学館
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.
SEIKOSEIKO
Copyright © 2026. SEIKO WATCH CORPORATION
ウィキペディアウィキペディア
Text is available under GNU Free Documentation License (GFDL).
Weblio辞書に掲載されている「ウィキペディア小見出し辞書」の記事は、WikipediaのC Sharpのデータ型 (改訂履歴)の記事を複製、再配布したものにあたり、GNU Free Documentation Licenseというライセンスの下で提供されています。

©2026 GRAS Group, Inc.RSS