1
x <- 1626307200

y = 0.034

x+y

I want to add these two numbers in r and save it as a float (1626307200.034). Both numbers are in numeric format. Tried several ways but didn't work

Niro Mal
  • 127
  • 7
  • The result is still of type `double`. R prints numbers with a maximum of `getOption("digits")` significant digits. You can increase this maximum with, e.g., `options(digits = 16)`. Now R prints `x + y` as `1626307200.034`. – Mikael Jagan Dec 10 '21 at 01:25
  • You can check the value with `sprintf("%.3f",x+y)`. – Andre Wildberg Dec 10 '21 at 01:27
  • just store `z <- x+y` z is the correct value. Probably you are wondering you cannot see it. Just know `z!=x`. Also you can get the decimal part of z ie `z%%1` – Onyambu Dec 10 '21 at 01:30
  • You can also use a `digits` argument directly in `print()` without changing your global options, e.g., `print(x + y, digits = 15)` – Gregor Thomas Dec 10 '21 at 04:11

1 Answers1

1

There is a command to allow R to display more digits:

options(digits = 15)
x <- 1626307200
y <- 0.034

z = x + y
z # 1626307200.034
Russ Conte
  • 124
  • 6