Netlogo 如何设置set sthg random float 1中的小数位数?

Netlogo 如何设置set sthg random float 1中的小数位数?,netlogo,Netlogo,当我使用set size random float 1时,如何将小数位数设置为2? 现在我有0.12433242,但我想要0.12(近似值)。 我知道有显示精度2,但我不知道如何将其包含在该命令中 谢谢Val,如果在显示命令(如show或print)中使用“precision”(精度),它只会影响显示值,而不会影响实际值。如果在set或let命令中使用“precision”,它将更改实际存储的值,并将其四舍五入到小数位数 以下是您可以尝试的代码: to setup let x rand

当我使用
set size random float 1
时,如何将小数位数设置为2? 现在我有
0.12433242
,但我想要
0.12
(近似值)。 我知道有
显示精度2
,但我不知道如何将其包含在该命令中

谢谢

Val,如果在显示命令(如show或print)中使用“precision”(精度),它只会影响显示值,而不会影响实际值。如果在set或let命令中使用“precision”,它将更改实际存储的值,并将其四舍五入到小数位数

以下是您可以尝试的代码:



to setup

  let x random-float 1
  type "original value has high precision: "  
  print x

  type "shown as low precision but value still high precision: " 
  print precision x 3

  type "confirm we didn't affect the original value: " 
  print x

  ;; actually change the value to 3 decimal places using "precision" in a set command
  set x precision x 3

  ;; confirm that worked
  type "New value actually has fewer decimals: " 
  print x

end