Decimal 乗算演算子
指定した 2 つの Decimal 値を乗算します。
returnValue = Decimal.op_Multiply(d1, d2)
[C#]
public static decimal operator *(decimald1,decimald2);
[C++]
public: static Decimal op_Multiply(Decimald1,Decimald2);
[JScript]
returnValue = d1 * d2;
[Visual Basic] Visual Basic では、この型で定義されている演算子を使用することができます。ただし、独自に定義することはできません。Multiply メソッドを Decimal 乗算演算子の代わりに使用することができます。
[JScript] JScript では、この型で定義されている演算子を使用することができます。ただし、独自に定義することはできません。
引数 [Visual Basic, JScript]
パラメータ [C#, C++]
戻り値
d1 に d2 を乗算した結果の Decimal 。
例外
例外の種類 | 条件 |
---|---|
OverflowException | 戻り値が MinValue より小さい値か、 MaxValue より大きい値です。 |
使用例
[Visual Basic, C#, C++] Decimal 値の複数のペアを作成し、各ペアの積を Multiplication 演算子で計算するコード例を次に示します。
' Example of the Decimal multiplication, division, and modulus
' operators.
Imports System
Imports Microsoft.VisualBasic
Module DecimalMulDivRemOpsDemo
Const dataFmt As String = "{0,-38}{1,31}"
' Display Decimal parameters and their product, quotient, and
' remainder.
Sub ShowDecimalProQuoRem( Left as Decimal, Right as Decimal )
Console.WriteLine( )
Console.WriteLine( dataFmt, "Decimal Left", Left )
Console.WriteLine( dataFmt, "Decimal Right", Right )
' The op_Multiply, op_Division, and op_Modulus operators must
' be explicitly coded in Visual Basic. If binary *, /, or
' Mod are used, other methods are called.
Console.WriteLine( dataFmt, _
"Decimal.op_Multiply( Left, Right )", _
Decimal.op_Multiply( Left, Right ) )
Console.WriteLine( dataFmt, _
"Decimal.op_Division( Left, Right )", _
Decimal.op_Division( Left, Right ) )
Console.WriteLine( dataFmt, _
"Decimal.op_Modulus( Left, Right )", _
Decimal.op_Modulus( Left, Right ) )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of the Decimal multiplication, " & _
"division, and modulus " & vbCrLf & "operators " & _
"generates the following output. It displays the " & _
"product, " & vbCrLf & "quotient, and remainder of " & _
"several pairs of Decimal objects." )
' Create pairs of Decimal objects.
ShowDecimalProQuoRem( 1000D, 7D )
ShowDecimalProQuoRem( -1000D, 7D )
ShowDecimalProQuoRem( _
new Decimal( 1230000000, 0, 0, False, 7 ), _
0.0012300D )
ShowDecimalProQuoRem( 12345678900000000D, _
0.0000000012345678D )
ShowDecimalProQuoRem( 123456789.0123456789D, _
123456789.1123456789D )
End Sub
End Module
' This example of the Decimal multiplication, division, and modulus
' operators generates the following output. It displays the product,
' quotient, and remainder of several pairs of Decimal objects.
'
' Decimal Left 1000
' Decimal Right 7
' Decimal.op_Multiply( Left, Right ) 7000
' Decimal.op_Division( Left, Right ) 142.85714285714285714285714286
' Decimal.op_Modulus( Left, Right ) 6
'
' Decimal Left -1000
' Decimal Right 7
' Decimal.op_Multiply( Left, Right ) -7000
' Decimal.op_Division( Left, Right ) -142.85714285714285714285714286
' Decimal.op_Modulus( Left, Right ) -6
'
' Decimal Left 123.0000000
' Decimal Right 0.00123
' Decimal.op_Multiply( Left, Right ) 0.151290000000
' Decimal.op_Division( Left, Right ) 100000.00
' Decimal.op_Modulus( Left, Right ) 0
'
' Decimal Left 12345678900000000
' Decimal Right 0.0000000012345678
' Decimal.op_Multiply( Left, Right ) 15241577.6390794200000000
' Decimal.op_Division( Left, Right ) 10000000729000059778004901.796
' Decimal.op_Modulus( Left, Right ) 0.000000000983
'
' Decimal Left 123456789.0123456789
' Decimal Right 123456789.1123456789
' Decimal.op_Multiply( Left, Right ) 15241578765584515.651425087878
' Decimal.op_Division( Left, Right ) 0.9999999991899999933660999449
' Decimal.op_Modulus( Left, Right ) 123456789.0123456789
[C#]
// Example of the decimal multiplication, division, and modulus
// operators.
using System;
class DecimalMulDivRemOpsDemo
{
const string dataFmt = " {0,-18}{1,31}";
// Display decimal parameters and their product, quotient, and
// remainder.
public static void ShowDecimalProQuoRem( decimal Left, decimal Right )
{
Console.WriteLine( );
Console.WriteLine( dataFmt, "decimal Left", Left );
Console.WriteLine( dataFmt, "decimal Right", Right );
Console.WriteLine( dataFmt, "Left * Right", Left * Right );
Console.WriteLine( dataFmt, "Left / Right", Left / Right );
Console.WriteLine( dataFmt, "Left % Right", Left % Right );
}
public static void Main( )
{
Console.WriteLine(
"This example of the decimal multiplication, division, " +
"and modulus \noperators generates the following " +
"output. It displays the product, \nquotient, and " +
"remainder of several pairs of decimal objects." );
// Create pairs of decimal objects.
ShowDecimalProQuoRem( 1000M, 7M );
ShowDecimalProQuoRem( -1000M, 7M );
ShowDecimalProQuoRem(
new decimal( 1230000000, 0, 0, false, 7 ), 0.0012300M );
ShowDecimalProQuoRem( 12345678900000000M,
0.0000000012345678M );
ShowDecimalProQuoRem( 123456789.0123456789M,
123456789.1123456789M );
}
}
/*
This example of the decimal multiplication, division, and modulus
operators generates the following output. It displays the product,
quotient, and remainder of several pairs of decimal objects.
decimal Left 1000
decimal Right 7
Left * Right 7000
Left / Right 142.85714285714285714285714286
Left % Right 6
decimal Left -1000
decimal Right 7
Left * Right -7000
Left / Right -142.85714285714285714285714286
Left % Right -6
decimal Left 123.0000000
decimal Right 0.0012300
Left * Right 0.15129000000000
Left / Right 100000
Left % Right 0
decimal Left 12345678900000000
decimal Right 0.0000000012345678
Left * Right 15241577.6390794200000000
Left / Right 10000000729000059778004901.796
Left % Right 0.000000000983
decimal Left 123456789.0123456789
decimal Right 123456789.1123456789
Left * Right 15241578765584515.651425087878
Left / Right 0.9999999991899999933660999449
Left % Right 123456789.0123456789
*/
[C++]
// Example of the Decimal multiplication, division, and modulus
// operators.
#using <mscorlib.dll>
using namespace System;
// Display Decimal parameters and their product, quotient, and
// remainder.
void ShowDecimalProQuoRem( Decimal Left, Decimal Right )
{
String* dataFmt = S" {0,-18}{1,31}";
Console::WriteLine( );
Console::WriteLine( dataFmt, S"Decimal Left", __box( Left ) );
Console::WriteLine( dataFmt, S"Decimal Right", __box( Right ) );
Console::WriteLine( dataFmt, S"Left * Right",
__box( Left * Right ) );
Console::WriteLine( dataFmt, S"Left / Right",
__box( Left / Right ) );
Console::WriteLine( dataFmt, S"Left % Right",
__box( Left % Right ) );
}
void main( )
{
Console::WriteLine(
S"This example of the Decimal multiplication, division, "
S"and modulus \noperators generates the following "
S"output. It displays the product, \nquotient, and "
S"remainder of several pairs of Decimal objects." );
// Create pairs of Decimal objects.
ShowDecimalProQuoRem( Decimal::Parse( S"1000" ),
Decimal::Parse( S"7" ) );
ShowDecimalProQuoRem( Decimal::Parse( S"-1000" ),
Decimal::Parse( S"7" ) );
ShowDecimalProQuoRem(
Decimal( 1230000000, 0, 0, false, 7 ),
Decimal::Parse( S"0.0012300" ) );
ShowDecimalProQuoRem( Decimal::Parse( S"12345678900000000" ),
Decimal::Parse( S"0.0000000012345678" ) );
ShowDecimalProQuoRem( Decimal::Parse( S"123456789.0123456789" ),
Decimal::Parse( S"123456789.1123456789" ) );
}
/*
This example of the Decimal multiplication, division, and modulus
operators generates the following output. It displays the product,
quotient, and remainder of several pairs of Decimal objects.
Decimal Left 1000
Decimal Right 7
Left * Right 7000
Left / Right 142.85714285714285714285714286
Left % Right 6
Decimal Left -1000
Decimal Right 7
Left * Right -7000
Left / Right -142.85714285714285714285714286
Left % Right -6
Decimal Left 123.0000000
Decimal Right 0.0012300
Left * Right 0.15129000000000
Left / Right 100000
Left % Right 0
Decimal Left 12345678900000000
Decimal Right 0.0000000012345678
Left * Right 15241577.6390794200000000
Left / Right 10000000729000059778004901.796
Left % Right 0.000000000983
Decimal Left 123456789.0123456789
Decimal Right 123456789.1123456789
Left * Right 15241578765584515.651425087878
Left / Right 0.9999999991899999933660999449
Left % Right 123456789.0123456789
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard