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,14
or he comes in with3,14
straightforward?– Marcus Nunes
is 3.14, that’s why I use
sub
to exchange the comma for a period. I saw that type.Converttem um parâmetro
Dec``` to indicate the decimal character, however it also rounds the result.– Everton da Rosa