1

In R, Why does this result in the accurate decimal value 999999.5.

1999999/2

But this results in a rounded whole number (1000001)?

2000001/2
Jacob Curtis
  • 738
  • 1
  • 7
  • 20

2 Answers2

2

It is about the number of digit for printing. You can set the number of digit to print in the print function.

print(2000001/2, digits = 8)
# [1] 1000000.5
www
  • 37,164
  • 12
  • 37
  • 72
2

It's just formatting. You can also set this option outside of the print function:

1999999 / 2
#> [1] 999999.5
2000001 / 2
#> [1] 1e+06
2000001 / 2 - 1000000 # The number is still full precision
#> [1] 0.5
options(digits=10)
2000001 / 2
#> [1] 1000000.5

Created on 2018-06-21 by the reprex package (v0.2.0).

Calum You
  • 13,710
  • 3
  • 20
  • 39