2
I have a script that receives a user value, via readLines. This value is a number (monetary value) with two decimal places that must be saved in a frame date.
However, when I convert the received value to Numeric, the R rounds to integer.
valor <- readLines("stdin", n = 1)
valor <- sub(",", ".", valor)#troca vírgula por ponto
valor <- as.numeric(as.character(valor))
I’ve also tried with type.convert, but the same behavior happens.
When you say "This value is a number (monetary value)", it means that the user enters a type value
R$ 3,14or he comes in with3,14straightforward?– Marcus Nunes
is 3.14, that’s why I use
subto exchange the comma for a period. I saw that type.Converttem um parâmetroDec``` to indicate the decimal character, however it also rounds the result.– Everton da Rosa