Reputation:
how can I set the number of decimals to 2 when I use set size random-float 1
?
Right now I have 0.12433242
but I would like 0.12
(approximated).
I know that there is show precision 2
, but I do not know how to include it in that command.
Thanks
Upvotes: 1
Views: 290
Reputation: 1473
Val, if you use "precision" in a display command, like show or print, it only affects the displayed value and doesn't touch the actual value. If you use "precision" in a set or let command, it will change the actual stored value, rounding it off to that many decimal places.
Here's code you can try:
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
Upvotes: 2