Difference between revisions of "VectorA:round"
From ComputerCraft Wiki
(Created page with "Returns a vector with all components rounded to the nearest integer Code example: local a = vector.new(1.4999, 1.5, 3.14) local c = a:round() print(c.x) print(c.y) p...") |
|||
Line 1: | Line 1: | ||
Returns a vector with all components rounded to the nearest integer | Returns a vector with all components rounded to the nearest integer | ||
+ | |||
+ | Code representation: | ||
+ | local a = vector.new(10.2, 1.5, 3.4999) | ||
+ | |||
+ | local c = vector.new( | ||
+ | math.floor(a.x + 0.5), | ||
+ | math.floor(a.y + 0.5), | ||
+ | math.floor(a.z + 0.5)) | ||
+ | --c.x = 10, c.y = 2, c.z = 3 | ||
Code example: | Code example: |
Revision as of 11:11, 23 February 2013
Returns a vector with all components rounded to the nearest integer
Code representation:
local a = vector.new(10.2, 1.5, 3.4999) local c = vector.new( math.floor(a.x + 0.5), math.floor(a.y + 0.5), math.floor(a.z + 0.5)) --c.x = 10, c.y = 2, c.z = 3
Code example:
local a = vector.new(1.4999, 1.5, 3.14) local c = a:round() print(c.x) print(c.y) print(c.z) --1 --2 --3