> t <- Sys.time()
> ct <- as.character(t)
> t - as.POSIXct(ct)
Time difference of 0.4370408 secs
The above example indicates that precision is lost when converting POSIXct to character.
How to preserve the exact value when converting to character so that when I convert back to POSIXct from character I get the original value?
Re: Converting decimal values to character? y = put (x, 10.4 );*I arbitrarily selected 4 decimal...which means 10.4 format allows for 10 characters, from which 4 are the decimal part; Good luck! Anca. Re: Converting decimal values to character?
With the EVAL operation, there are three options: If no decimal positions exist in the field, you can use the C runtime function atoll () to convert from character to numeric. If you are on V5R2 or later, you can use the %INT built-in function to do the same thing.
If you are on V5R2 or later, you can use the %INT built-in function to do the same thing. If the value contains decimal positions, you need to use the CharToNum () function in the RPG ToolKit; if you are on V5R2 or later, the %DEC built-in function will do a similar job to CharToNum, but it's not as good in all situations.
You can use the little-known "X" edit code to convert numeric fields to character and retain the leading zeros on the value. Then, when used in conjunction with the EVAL operation or the assignment (equals sign) on /FREE syntax, it converts a number to character and zero fills the result.
You can set the option digits.secs
to 6 (its maximum value).
options(digits.secs = 6)
t <- Sys.time()
ct <- as.character(t)
t - as.POSIXct(ct)
Time difference of 0 secs
You can use format
with %OS6
, to give seconds in digits, but still there will be sometimes a difference:
t <- Sys.time()
ct <- format(t, "%Y-%m-%d %H:%M:%OS6")
t - as.POSIXct(ct)
#Time difference of 0 secs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With