R floating point number precision being lost on coversion from character

前端 未结 1 670
不知归路
不知归路 2021-01-13 06:34

I have a large floating point number as a character like so

  x<-\"5374761693.91823\";

On doing

 as.numeric(x); 


        
相关标签:
1条回答
  • 2021-01-13 07:30

    use digits argument in print to see the actual number:

    > print(as.numeric(x), digits=15)
    [1] 5374761693.91823
    

    options is another alternative:

    > options(digits=16)
    > as.numeric(x)
    [1] 5374761693.91823
    
    > # assignments
    > options(digits=16)
    > y <- as.numeric(x)
    > y
    [1] 5374761693.91823
    
    z <- print(as.numeric(x), digits=15)
    z
    
    0 讨论(0)
提交回复
热议问题