dec2bcd {convertBCD} | R Documentation |
The input decimal values are converted to one or two vectors of class "raw" , representing an integer and optionally a decimal portion of a number.
dec2bcd(x, endian = c("little", "big"))
x |
Decimal numbers. Can be one of the following classes: numeric, bigz, character. |
endian |
The order of bytes desired in the raw BCD output. |
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 are returned separately. .
A list containing: intx , a vector of strings representing the integer parts of the decimal number decx, a vector of strings representing the decimal parts of the decimal number, if any.
Carl Witthoft, carl@witthoft.com
foo <- dec2bcd('37.852')
bar <- bcd2dec(foo$xint[[1]],foo$xdec[[1]])