Philipp Upravitelev
2018-11-28 13:49:42 UTC
Dear colleagues,
could you help me with the function base::round()? I can't understand how
it works.
For example, when I want to round 0.015 to the second digit, base::round()
returns 0.02.
Therefore, according to the arithmetic rules, rounded 0.014 to the second
digit is 0.01. Also, the round() function in other programming languages
(Python, Java) returns 0.01. It is a bit counterintuitive but
mathematically correct.
I'll be very pleased if you could help me to figure out why the
base::round(0.015, 2) returns 0.02 and what is the purpose of this feature.
Best regards,
Philipp Upravitelev
[[alternative HTML version deleted]]
______________________________________________
R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
could you help me with the function base::round()? I can't understand how
it works.
For example, when I want to round 0.015 to the second digit, base::round()
returns 0.02.
sprintf('%.20f', 0.015)
[1] "0.01499999999999999944"0.015 == 0.01499999999999999944
[1] TRUEround(0.015, 2)
[1] 0.02Therefore, according to the arithmetic rules, rounded 0.014 to the second
digit is 0.01. Also, the round() function in other programming languages
(Python, Java) returns 0.01. It is a bit counterintuitive but
mathematically correct.
I'll be very pleased if you could help me to figure out why the
base::round(0.015, 2) returns 0.02 and what is the purpose of this feature.
Best regards,
Philipp Upravitelev
[[alternative HTML version deleted]]
______________________________________________
R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.