Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original
Este tópico ainda não foi avaliado como - Avalie este tópico

Decimal Estrutura

Representa um número decimal.

Namespace:  System
Assembly:  mscorlib (em mscorlib. dll)
[SerializableAttribute]
[ComVisibleAttribute(true)]
public struct Decimal : IFormattable, IComparable, 
	IConvertible, IComparable<decimal>, IEquatable<decimal>

The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335.The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors.

A decimal número is a ponto flutuante valor that consists of a assinar, a valor numeric onde each dígito in the Ranges valor from 0 to 9, and a fator de escala that the posição of a flutuante indicates ponto decimal that separates the integral and fracionário parts of the valor numeric.

The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction.O fator de escala é implicitamente o número 10, elevado a uma expoente variando de 0 a 28.Therefore, the binary representation of a Decimal value is of the form, ((-296 to 296) / 10(0 to 28)), where -296-1 is equal to MinValue, and 296-1 is equal to MaxValue.

The scaling factor also preserves any trailing zeroes in a Decimal number.Trailing zeroes do not affect the value of a Decimal number in arithmetic or comparison operations.However, trailing zeroes can be revealed by the ToString method if an appropriate format string is applied.

Considerações sobre de conversão

This type provides methods that convert Decimal values to and from type Char, SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, and UInt64.Conversions from other types to Decimal are widening conversions that never lose information or throw exceptions.

Conversions from Decimal to other types are narrowing conversions that round the Decimal value to the nearest integer value toward zero.If the result of the conversion is not representable in the destination type, an OverflowException is thrown.

This type provides methods that convert Decimal values to and from Single and Double.Conversions from Decimal to Single or Double are narrowing conversions that might lose precision but not information about the magnitude of the converted value.The conversão will not Gerar uma Exceção.

Conversions from Single or Double to Decimal throw an OverflowException if the result of the conversion is not representable as a Decimal.

Interfaces implementada

Esse tipo implementa interfaces IComparable, IComparable<T>, IFormattable e IConvertible.Use the Convert class for conversions instead of this type's explicit interface member implementation of IConvertible.

The following code example demonstrates the use of Decimal.

	/// <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>
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";
		}
	}


Todos os membros desse tipo são segmento seguro.Os membros que aparecem para modificar o estado da instância, na verdade, retornam uma nova instância inicializada com o novo valor.Como com qualquer outro tipo, leitura e gravação a uma variável compartilhada que contém uma instância desse tipo devem ser protegida por um bloqueio para garantir segurança de segmentos.

Observação de cautelaCuidado:

Assigning an instância of this tipo is not isento de segmentos on All hardware Plataformas because the binário representation of that instância Might be Too Large to atribuir in a single operação atômica.

Isso foi útil para você?
(1500 caracteres restantes)

Contribuições da comunidade

ADICIONAR
© 2013 Microsoft. Todos os direitos reservados.