다음을 통해 공유


Decimal.Negate 메서드

지정된 Decimal 값과 음수 1을 곱한 결과를 반환합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Shared Function Negate ( _
    d As Decimal _
) As Decimal
‘사용 방법
Dim d As Decimal
Dim returnValue As Decimal

returnValue = Decimal.Negate(d)
public static decimal Negate (
    decimal d
)
public:
static Decimal Negate (
    Decimal d
)
public static Decimal Negate (
    Decimal d
)
public static function Negate (
    d : decimal
) : decimal

매개 변수

반환 값

d 값을 가지며 부호는 반대인 Decimal입니다. - 또는 - d가 0이면 0입니다.

예제

다음 코드 예제에서는 Negate 메서드를 사용하여 일부 Decimal 값의 부호를 변경합니다.

' Example of the Decimal.Negate, Decimal.Floor, and Decimal.Truncate 
' methods. 
Imports System
Imports Microsoft.VisualBasic

Module DecimalFloorNegTruncDemo
    
    Const dataFmt As String = "{0,-30}{1,26}"

    ' Display Decimal parameters and their product, quotient, and 
    ' remainder.
    Sub ShowDecimalFloorNegTrunc( Argument as Decimal )

        Console.WriteLine( )
        Console.WriteLine( dataFmt, "Decimal Argument", Argument )
        Console.WriteLine( dataFmt, _
            "Decimal.Negate( Argument )", _
            Decimal.Negate( Argument ) )
        Console.WriteLine( dataFmt, _
            "Decimal.Floor( Argument )", _
            Decimal.Floor( Argument ) )
        Console.WriteLine( dataFmt, _
            "Decimal.Truncate( Argument )", _
            Decimal.Truncate( Argument ) )
    End Sub

    Sub Main( )
        Console.WriteLine( "This example of the " & vbCrLf & _
            "  Decimal.Negate( Decimal ), " & vbCrLf & _
            "  Decimal.Floor( Decimal ), and " & vbCrLf & _
            "  Decimal.Truncate( Decimal ) " & vbCrLf & _
            "methods generates the following output." )

        ' Create pairs of Decimal objects.
        ShowDecimalFloorNegTrunc( 0D ) 
        ShowDecimalFloorNegTrunc( 123.456D ) 
        ShowDecimalFloorNegTrunc( -123.456D ) 
        ShowDecimalFloorNegTrunc( _
            new Decimal( 1230000000, 0, 0, True, 7 ) )
        ShowDecimalFloorNegTrunc( -9999999999.9999999999D )
    End Sub
End Module 

' This example of the
'   Decimal.Negate( Decimal ),
'   Decimal.Floor( Decimal ), and
'   Decimal.Truncate( Decimal )
' methods generates the following output.
' 
' Decimal Argument                                       0
' Decimal.Negate( Argument )                             0
' Decimal.Floor( Argument )                              0
' Decimal.Truncate( Argument )                           0
' 
' Decimal Argument                                 123.456
' Decimal.Negate( Argument )                      -123.456
' Decimal.Floor( Argument )                            123
' Decimal.Truncate( Argument )                         123
' 
' Decimal Argument                                -123.456
' Decimal.Negate( Argument )                       123.456
' Decimal.Floor( Argument )                           -124
' Decimal.Truncate( Argument )                        -123
' 
' Decimal Argument                            -123.0000000
' Decimal.Negate( Argument )                   123.0000000
' Decimal.Floor( Argument )                           -123
' Decimal.Truncate( Argument )                        -123
' 
' Decimal Argument                  -9999999999.9999999999
' Decimal.Negate( Argument )         9999999999.9999999999
' Decimal.Floor( Argument )                   -10000000000
' Decimal.Truncate( Argument )                 -9999999999
// Example of the decimal.Negate, decimal.Floor, and decimal.Truncate 
// methods. 
using System;

class DecimalFloorNegTruncDemo
{
    const string dataFmt = "{0,-30}{1,26}";

    // Display decimal parameters and the method results.
    public static void ShowDecimalFloorNegTrunc( decimal Argument )
    {
        Console.WriteLine( );
        Console.WriteLine( dataFmt, "decimal Argument", Argument );
        Console.WriteLine( dataFmt, "decimal.Negate( Argument )", 
            decimal.Negate( Argument ) );
        Console.WriteLine( dataFmt, "decimal.Floor( Argument )", 
            decimal.Floor( Argument ) );
        Console.WriteLine( dataFmt, "decimal.Truncate( Argument )", 
            decimal.Truncate( Argument ) );
    }

    public static void Main( )
    {
        Console.WriteLine( "This example of the \n" +
            "  decimal.Negate( decimal ), \n" +
            "  decimal.Floor( decimal ), and \n" +
            "  decimal.Truncate( decimal ) \n" +
            "methods generates the following output." );

        // Create pairs of decimal objects.
        ShowDecimalFloorNegTrunc( 0M );
        ShowDecimalFloorNegTrunc( 123.456M );
        ShowDecimalFloorNegTrunc( -123.456M );
        ShowDecimalFloorNegTrunc( 
            new decimal( 1230000000, 0, 0, true, 7 ) );
        ShowDecimalFloorNegTrunc( -9999999999.9999999999M );
    }
}

/*
This example of the
  decimal.Negate( decimal ),
  decimal.Floor( decimal ), and
  decimal.Truncate( decimal )
methods generates the following output.

decimal Argument                                       0
decimal.Negate( Argument )                             0
decimal.Floor( Argument )                              0
decimal.Truncate( Argument )                           0

decimal Argument                                 123.456
decimal.Negate( Argument )                      -123.456
decimal.Floor( Argument )                            123
decimal.Truncate( Argument )                         123

decimal Argument                                -123.456
decimal.Negate( Argument )                       123.456
decimal.Floor( Argument )                           -124
decimal.Truncate( Argument )                        -123

decimal Argument                            -123.0000000
decimal.Negate( Argument )                   123.0000000
decimal.Floor( Argument )                           -123
decimal.Truncate( Argument )                        -123

decimal Argument                  -9999999999.9999999999
decimal.Negate( Argument )         9999999999.9999999999
decimal.Floor( Argument )                   -10000000000
decimal.Truncate( Argument )                 -9999999999
*/ 
// Example of the Decimal::Negate, Decimal::Floor, and 
// Decimal::Truncate methods. 
using namespace System;

// Display Decimal parameters and the method results.
void ShowDecimalFloorNegTrunc( Decimal Argument )
{
   String^ dataFmt = "{0,-30}{1,26}";
   Console::WriteLine();
   Console::WriteLine( dataFmt, "Decimal Argument", Argument );
   Console::WriteLine( dataFmt, "Decimal::Negate( Argument )", Decimal::Negate( Argument ) );
   Console::WriteLine( dataFmt, "Decimal::Floor( Argument )", Decimal::Floor( Argument ) );
   Console::WriteLine( dataFmt, "Decimal::Truncate( Argument )", Decimal::Truncate( Argument ) );
}

int main()
{
   Console::WriteLine( "This example of the \n"
   "  Decimal::Negate( Decimal ), \n"
   "  Decimal::Floor( Decimal ), and \n"
   "  Decimal::Truncate( Decimal ) \n"
   "methods generates the following output." );
   
   // Create pairs of Decimal objects.
   ShowDecimalFloorNegTrunc( Decimal::Parse( "0" ) );
   ShowDecimalFloorNegTrunc( Decimal::Parse( "123.456" ) );
   ShowDecimalFloorNegTrunc( Decimal::Parse( "-123.456" ) );
   ShowDecimalFloorNegTrunc( Decimal(1230000000,0,0,true,7) );
   ShowDecimalFloorNegTrunc( Decimal::Parse( "-9999999999.9999999999" ) );
}

/*
This example of the
  Decimal::Negate( Decimal ),
  Decimal::Floor( Decimal ), and
  Decimal::Truncate( Decimal )
methods generates the following output.

Decimal Argument                                       0
Decimal::Negate( Argument )                            0
Decimal::Floor( Argument )                             0
Decimal::Truncate( Argument )                          0

Decimal Argument                                 123.456
Decimal::Negate( Argument )                     -123.456
Decimal::Floor( Argument )                           123
Decimal::Truncate( Argument )                        123

Decimal Argument                                -123.456
Decimal::Negate( Argument )                      123.456
Decimal::Floor( Argument )                          -124
Decimal::Truncate( Argument )                       -123

Decimal Argument                            -123.0000000
Decimal::Negate( Argument )                  123.0000000
Decimal::Floor( Argument )                          -123
Decimal::Truncate( Argument )                       -123

Decimal Argument                  -9999999999.9999999999
Decimal::Negate( Argument )        9999999999.9999999999
Decimal::Floor( Argument )                  -10000000000
Decimal::Truncate( Argument )                -9999999999
*/
// Example of the decimal.Negate, decimal.Floor, and decimal.Truncate 
// methods. 
import System.*;

class DecimalFloorNegTruncDemo
{
    private static String dataFmt = "{0,-30}{1,26}";

    // Display decimal parameters and the method results.
    public static void ShowDecimalFloorNegTrunc(System.Decimal argument)
    {
        Console.WriteLine();
        Console.WriteLine(dataFmt, "decimal argument", argument);
        Console.WriteLine(dataFmt, "decimal.Negate( argument )",
            System.Decimal.Negate(argument));
        Console.WriteLine(dataFmt, "decimal.Floor( argument )", 
            System.Decimal.Floor(argument));
        Console.WriteLine(dataFmt, "decimal.Truncate( argument )",
        System.Decimal.Truncate(argument));
    } //ShowDecimalFloorNegTrunc

    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the \n"
            + "  decimal.Negate( decimal ), \n" 
            + "  decimal.Floor( decimal ), and \n" 
            + "  decimal.Truncate( decimal ) \n" 
            + "methods generates the following output."));

        // Create pairs of decimal objects.
        ShowDecimalFloorNegTrunc(System.Convert.ToDecimal(0));
        ShowDecimalFloorNegTrunc(System.Convert.ToDecimal(123.456));
        ShowDecimalFloorNegTrunc(System.Convert.ToDecimal(-123.456));
        ShowDecimalFloorNegTrunc(new System.Decimal(1230000000, 0, 0, true,
            System.Convert.ToByte(7)));
        ShowDecimalFloorNegTrunc(System.Convert.ToDecimal(
            -9999999999.9999999999));
    } //main
} //DecimalFloorNegTruncDemo

/*
This example of the
  decimal.Negate( decimal ),
  decimal.Floor( decimal ), and
  decimal.Truncate( decimal )
methods generates the following output.

decimal argument                                       0
decimal.Negate( argument )                             0
decimal.Floor( argument )                              0
decimal.Truncate( argument )                           0

decimal argument                                 123.456
decimal.Negate( argument )                      -123.456
decimal.Floor( argument )                            123
decimal.Truncate( argument )                         123

decimal argument                                -123.456
decimal.Negate( argument )                       123.456
decimal.Floor( argument )                           -124
decimal.Truncate( argument )                        -123

decimal argument                            -123.0000000
decimal.Negate( argument )                   123.0000000
decimal.Floor( argument )                           -123
decimal.Truncate( argument )                        -123

decimal argument                  -9999999999.9999999999
decimal.Negate( argument )         9999999999.9999999999
decimal.Floor( argument )                   -10000000000
decimal.Truncate( argument )                 -9999999999
*/

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Decimal 구조체
Decimal 멤버
System 네임스페이스