Search code examples
rfloating-pointnumericdigitsoutput-formatting

Add integer to a float and get the output as float in r


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


Solution

  • 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