使用 round 函数对复数进行取整报错:ERROR: type DataType has no field round
技术分享
发布于 2025-07-10 10:51:25
查看 1过去327天
使用 round 函数时需要配置舍入方向属性为“RoundNearestTiesAway”,四舍五入后再通过 convert 函数将浮点数转为整数。可参考以下代码。
a = rand(4,1)+im*rand(4,1)
b = a*100
# aInt = Int.round.(b)
aInt = convert.(Complex{Int64},round.(b,RoundNearestTiesAway))
运行上面代码,得到四舍五入的结果:


在命令行中输入变量 b 并回车,可以看到变量 b 的值:

比较数值,可以看到得到了正确的四舍五入整数结果:

所属专栏:Syslab基础平台
产品信息:Syslab科学计算环境