BinaryReader: ReadDecimal

ReadDecimal

Reads a decimal value from the current stream and advances the current position of the stream by sixteen bytes.



 Public Function ReadDecimal ( ) As Variant

Return Values

Variant -  A decimal value read from the current stream.

Remarks

BinaryReader does not restore the file position after an unsuccessful read.

BinaryReader reads this data type in little-endian format.

The decimal type is created from sixteen bytes using the same layout as the .NET decimal type. The layout is different than that of Visual Basic as shown in the following table.

Framework Layout
Visual Basic bytes 0-1: Variant sub-type information (vbDecimal)
bytes 2: precision (0 to 28)
bytes 3: sign (&H80 is negative)
bytes 4-7: high 32 bits in the 96-bit value
bytes 8-11: low 32 bits in the 96-bit value
bytes 12-15: middle 32 bits in the 96-bit value
.NET Framework bytes 0-3: low 32 bits in the 96-bit value
bytes 4-7: middle 32 bits in the 96-bit value
bytes 8-11: high 32 bits in the 96-bit value
bytes 12-13: unused (zero)
bytes 14: precision (0 to 28)
bytes 15: sign (&H80 is negative)

If the sign byte is non-zero, then the Decimal will be set as negative.

Exceptions

Exception Condition
EndOfStreamExceptionThe end of the stream is reached.
ObjectDisposedExceptionThe stream is closed.
IOExceptionAn I/O error occurs.
ArgumentOutOfRangeException The decimal precision is greater than 28.

See Also

Project CorLib Overview

Class BinaryReader Overview