How does R round numbers with the round()
function?
For example:
round(0.345, 2)
# [1] 0.34
I would expect 0.35.
round(0.3455, 3)
# [1] 0.346
This is what's expected.
How does R round numbers with the round()
function?
For example:
round(0.345, 2)
# [1] 0.34
I would expect 0.35.
round(0.3455, 3)
# [1] 0.346
This is what's expected.
One hack to that function I've used before to get what you expect out of it... If the number has 5 decimal accuracy, multiply by your desired # of decimals to round off (I.e. *1000), call as.integer() on the result, then multiply by 0.001. A simple function follows this psuedo code:
Make your own function with an input for the # of decimals desired. Multiply the input value by 10^(# decimals input). Do an as.integer() on this value. Now multiply by 10^(-# decimals input). Return this value.