Given one or two input vectors of class "raw" , representing an integer and optionally a decimal portion of a number, the decimal values are returned.
bcd2dec(x, xdec = NULL, mergex = TRUE, endian = c("little", "big"))
A list with elements:
intx , character strings representing the decimal numbers produced or, if mergex == FALSE
, the integer portions of the numbers.
decx , set to NULL unless mergex == FALSE
, in which case character strings representing the decimal portions of the numbers generated.
The vector of bytes containing the BCD representation of the integer portion of a value. Must be of class 'raw'.
The vector of bytes containing the BCD representation of the decimal portion of a value Must be of class 'raw'. The default is NULL
.
A logical value. If TRUE
, The integer and decimal parts are combined to return a single number. Otherwise the integer and decimal parts are returned separately.
The order of bytes in the raw BCD input.
Carl Witthoft, carl@witthoft.com
The BCD format reserves a full byte for each character (number) in an input value. While this is memory-expensive, it guarantees the exact value is stored, unlike class numeric
or others, which are subject to binary expansion rounding errors.
There is no standard for indicating the location of a decimal point in BCD data, which is why the integer and decimal portion must be entered separately here.
bcdToInteger
dec2bcd
foo <- dec2bcd('37.852')
bar <- bcd2dec(foo$xint[[1]],foo$xdec[[1]])
Run the code above in your browser using DataLab