decimal

System.Decimal
Exact Precision Floating Point (1 E -28 to 7.9 E 28)
29 significant digits.
The default value is 0.

decimal myDecimal; 
System.Decimal myDecimal;

Explicit Data Type

You can append literal constants with the letter "M" or "m" when you need to specify this type of literal.

decimal myDecimal = 1.6m;                         'suffix is necessary  
decimal myDecimal = 1.6M; 'suffix is necessary

Converting

// Decimal to Integer 
decimal myDecimal = 1.6M;
int myInteger = (int)myDecimal;

// Decimal to Double
decimal myDecimal = 1.6M;
double myDouble = (double)myDecimal;

// Decimal to Float
decimal myDecimal = 1.6M;
float myFloat = (float)myDecimal;

Examples


System.Diagnostics.Debug.Print myDecimal           '= 1.2345  

VBA Currency Equivalent

The Currency data type in VBA has been replaced with the Decimal data type in C#.
In most cases these will be interchangeable however they do actually differ in their precision.
The Decimal data type in .NET is more accurate than the VBA Currency data type.


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext