gpt4 book ai didi

R float 精度在从字符转换时丢失

转载 作者:行者123 更新时间:2023-12-04 10:51:44 25 4
gpt4 key购买 nike

我有一个很大的浮点数作为这样的字符

  x<-"5374761693.91823";

在做
 as.numeric(x); 

我得到以下输出
   5374761694

我想在转换时保留数字的浮点性质。

最佳答案

使用 digits参数在 print查看实际数字:

> print(as.numeric(x), digits=15)
[1] 5374761693.91823
options是另一种选择:
> 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

关于R float 精度在从字符转换时丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17878703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com