Table of Contents

Class VBDecimalType

Namespace
RDCore.SDK.Model.Types
Assembly
RDCore.SDK.dll

A VBNumericType<T> representing the Decimal data type.

public sealed record VBDecimalType : VBNumericType<decimal>, IEquatable<VBType>, IEquatable<VBIntrinsicType>, IEquatable<VBNumericType>, IEquatable<VBNumericType<decimal>>, IFixedPointNumericType, INumericType, IEquatable<VBDecimalType>
Inheritance
VBDecimalType
Implements
Inherited Members
Extension Methods

Remarks

The managed type of a value of this data type is decimal.
👉 Implements IFixedPointNumericType.

Constructors

VBDecimalType()

A VBNumericType<T> representing the Decimal data type.

public VBDecimalType()

Remarks

The managed type of a value of this data type is decimal.
👉 Implements IFixedPointNumericType.

Properties

DefaultValue

Gets the default value for this data type.

public override VBTypedValue DefaultValue { get; }

Property Value

VBTypedValue

Remarks

⚠️ Derived types must back the implementation of this property with a thread-safe private static readonly Lazy<T>. Failure to do so would lock up the static context initialization of the StaticSymbol symbols.

ManagedMaxValue

Gets the maximum representable managed (.net) value for this data type.

public override double ManagedMaxValue { get; }

Property Value

double

ManagedMinValue

Gets the minimum representable managed (.net) value for this data type.

public override double ManagedMinValue { get; }

Property Value

double

MaxValue

Gets the maximum representable value for this data type.

public static VBDecimalValue MaxValue { get; }

Property Value

VBDecimalValue

MinValue

Gets the minimum representable value for this data type.

public static VBDecimalValue MinValue { get; }

Property Value

VBDecimalValue

TypeInfo

The Decimal data type.

public static VBDecimalType TypeInfo { get; }

Property Value

VBDecimalType

Zero

Gets the value 0 (zero) representation of this data type.

public static VBDecimalValue Zero { get; }

Property Value

VBDecimalValue

Methods

CreateValue(IBindingHandle)

Creates a value of this type bound to handle.

public override VBTypedValue CreateValue(IBindingHandle handle)

Parameters

handle IBindingHandle

Returns

VBTypedValue

Remarks

The base implementation throws: only types that can hold a runtime value override this (matches the intent of the removed VBTypedValueFactory.CreateValue(VBType) switch, which returned null for the rest).

CreateValue(double)

Creates a Decimal value of a Double, rounded to 15 significant digits as FromDouble(double) rounds it.

public override VBNumericTypedValue CreateValue(double value)

Parameters

value double

The Double to convert.

Returns

VBNumericTypedValue

Exceptions

OverflowException

value is an infinity, a NaN, or past the range of a Decimal.

FromDouble(double)

Converts a Double to a Decimal as MS-VBA does: the value rounded to 15 significant digits, a tie to the even digit (MS-VBAL §5.5.1.2.1).

public static decimal FromDouble(double value)

Parameters

value double

The Double to convert.

Returns

decimal

The Decimal: 0.1 is 0.1, and 1 / 3 is 0.333333333333333. A value too small for the 28 decimal places of a Decimal is 0.

Remarks

MS-VBAL §5.5.1.2.1 rounds the value to the nearest Decimal. MS-VBA first rounds it to the 15 significant digits a Double holds, so that no digit of its binary representation past them reaches the Decimal (observed in Excel). The result does not depend on the .NET version.

Exceptions

OverflowException

value is an infinity, a NaN, or past the range of a Decimal.

FromSingle(float)

Converts a Single to a Decimal as MS-VBA does: the value rounded to 7 significant digits, a tie to the even digit (MS-VBAL §5.5.1.2.1).

public static decimal FromSingle(float value)

Parameters

value float

The Single to convert.

Returns

decimal

The Decimal: 0.1 is 0.1, and 16777217, which is the Single 16777216, is 16777220. A value too small for the 28 decimal places of a Decimal is 0.

Remarks

MS-VBAL §5.5.1.2.1 rounds the value to the nearest Decimal. MS-VBA first rounds it to the 7 significant digits a Single holds (observed in Excel). A Single converted to a Double first keeps 15 digits instead: CDec(CDbl(CSng(0.1))) is 0.100000001490116. The result does not depend on the .NET version.

Exceptions

OverflowException

value is an infinity, a NaN, or past the range of a Decimal.

Holds(double)

Whether a double is within the range of this type (MS-VBAL 5.5.1.2.1): one a value of this type can be made of (CreateValue(double)) without leaving the range.

public override bool Holds(double value)

Parameters

value double

The value. NaN is within no range.

Returns

bool

Remarks

👉 The base is within ManagedMinValue and ManagedMaxValue, both included, which is right for a type whose bounds are double values. A type whose bound is not one has, as its ManagedMaxValue or ManagedMinValue, the double nearest it, which can be past it: that type overrides this, and leaves out such a bound.

ToDouble(decimal)

Converts a Decimal to a Double as MS-VBA does: the 96-bit integer of the Decimal made a Double, then divided by the Double power of ten of its scale (MS-VBAL §5.5.1.2.1).

public static double ToDouble(decimal value)

Parameters

value decimal

The Decimal to convert.

Returns

double

The Double. It is the Double nearest the value, or the other Double next to the value when the value is close to halfway between the two: CDbl(CDec("0.000708160857053799161669089")) is the Double above it, where the nearest is the one below.

Remarks

MS-VBAL §5.5.1.2.1 rounds the value to the nearest Double. MS-VBA rounds it twice, as the OLEAUT32 VarR8FromDec function does (observed in Excel). CDbl, a Let to a Double and the ^ operator make this Double, and so does a conversion of a Decimal to a whole number before it rounds: CLng(CDec("2.50000000000000000000000001")) is 2. The result does not depend on the .NET version.

ToSingle(decimal)

Converts a Decimal to a Single as MS-VBA does: the Double that ToDouble(decimal) makes, rounded to the nearest Single (MS-VBAL §5.5.1.2.1).

public static float ToSingle(decimal value)

Parameters

value decimal

The Decimal to convert.

Returns

float

The Single: CSng(CDec("1.000000059604644775390626")) is 1, where the nearest Single is the one above 1.

Remarks

MS-VBAL §5.5.1.2.1 rounds the value to the nearest Single. MS-VBA rounds the Double it makes first, as the OLEAUT32 VarR4FromDec function does (observed in Excel). The result does not depend on the .NET version.