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
  • 788
  • 1
  • 8
  • 22

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
  • 38,575
  • 12
  • 48
  • 84
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
  • 14,687
  • 4
  • 23
  • 42