AlypiaJoin Date: 2017-06-25 Post Count: 105 |
Hey Scripters, I can't find any information on such a simple question.
I need to round the exact values of my variables. The reason because, I need to get the X, Y, and Z positions of a part, and then get them a second time after .1 seconds. If the two calculations are similar (ie; the part is near stationary,) then an event will fire.
Due to the physics engine, the exact value of X, Y, and Z, added together, will constantly change, even if the part is seemingly "stationary." The values tend to rapidly change after the one hundredth of a decimal place, so I ideally need to round my values to the nearest one hundredth.
How do I round values?
⚜ 𝕬𝖑𝖞𝖕𝖎𝖆 |
|
|
math.floor(x) will round x down
math.ceil(x) will round x up
math.floor(x + 0.5) will round x |
|
|
number = 1.543565
print(round(number, 2))
# outputs 1.54 |
|
AlypiaJoin Date: 2017-06-25 Post Count: 105 |
Thank you, Gigabytes.
⚜ 𝕬𝖑𝖞𝖕𝖎𝖆 |
|
|
Arent you gonna thank me /s |
|
AlypiaJoin Date: 2017-06-25 Post Count: 105 |
I would thank you Beatable, if I was using Python, but I'm using Lua... Lmao
⚜ 𝕬𝖑𝖞𝖕𝖎𝖆 |
|
|
Who said anything about Lua... |
|
AlypiaJoin Date: 2017-06-25 Post Count: 105 |
You're not wrong... >_>
⚜ 𝕬𝖑𝖞𝖕𝖎𝖆 |
|
joshxieJoin Date: 2017-01-15 Post Count: 48 |
roblox uses lua
if you asked on a scripting forum on roblox, which uses lua, it's pretty clear you're asking for lua |
|
|
No where on this subforum rules or op's thread does it say anything about lua. She could be talking about Ruby for all i know. |
|
joshxieJoin Date: 2017-01-15 Post Count: 48 |
you silly goose,
she's talking about objective-c |
|
|
rules say for roblox scripting dummy
|
|
|
no, there is no way shes not talking about baisc |
|
|
on second thought it seems as she is talking about go |
|
Dollar500Join Date: 2013-01-12 Post Count: 504 |
If you want to round to a decimal place you can do this:
math.ceil(Value * 10) / 10 |
|
|
AlypiaJoin Date: 2017-06-25 Post Count: 105 |
1) Why are there still replies here? Lmao
2) @Beatable; In my original post, I said:
"Due to the physics engine, the exact value of X, Y, and Z, added together, will constantly change, even if the part is seemingly "stationary.""
Last time I checked, Python coding from scratch, didn't have a built-in physics engine. It's not like I just asked how to round a value, and nothing else.
⚜ 𝕬𝖑𝖞𝖕𝖎𝖆 |
|
AlypiaJoin Date: 2017-06-25 Post Count: 105 |
@Dollar:
Thank you very much!
⚜ 𝕬𝖑𝖞𝖕𝖎𝖆 |
|
|