kaddad14
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 649 |
|
|
| 27 Jan 2017 03:55 PM |
| Any way to turn a decimal into an integer? |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2017 03:56 PM |
round it or just remove the decimal point? you can just call math.floor() on it if the number is 5.000 or something like that
|
|
|
| Report Abuse |
|
|
|
| 27 Jan 2017 03:57 PM |
myFloat = 0.25; math.floor(myFloat);
I think you can also do this, but that's Python:
myFloat = 0.25; print(int(myFloat));
Want to be supported by developers in a positive atmosphere? Then join Studio BSD: roblox.com/My/Groups.aspx?gid=1013064 |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2017 03:58 PM |
| roundedX = math.floor(0.5 + x) |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 27 Jan 2017 03:58 PM |
Lua 5.1 doesn't have integers.
|
|
|
| Report Abuse |
|
|
kaddad14
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 649 |
|
|
| 27 Jan 2017 04:08 PM |
| If I got a number like local x = ########### could I ## # =math.floor(x) |
|
|
| Report Abuse |
|
|
kaddad14
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 649 |
|
|
| 27 Jan 2017 04:18 PM |
| OH NO I SAID A DECIMAL!! How bad of me... anyway If I got a decimal like 4 . 5595959 could i do math.floor(x)? |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2017 04:19 PM |
That'd round down ONLY.
To do a correct round, do math.floor(0.5+x) |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2017 04:19 PM |
math.floor rounds a float downwards to a whole number. math.ceil rounds a float upwards to a whole number.
example:
math.floor(1.5); -- 1 math.ceil(1.5); -- 2
Want to be supported by developers in a positive atmosphere? Then join Studio BSD: roblox.com/My/Groups.aspx?gid=1013064 |
|
|
| Report Abuse |
|
|
kaddad14
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 649 |
|
|
| 27 Jan 2017 04:35 PM |
| ok well how would I turn a number positive? (like x could be - or +) |
|
|
| Report Abuse |
|
|
| |
|
|
| 27 Jan 2017 04:36 PM |
| math.abs(x) will make sure the number is always positive (or 0 ;)) |
|
|
| Report Abuse |
|
|
kaddad14
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 649 |
|
| |
|
|
| 28 Jan 2017 07:23 AM |
Thanks as well for making me understand absolute value
Want to be supported by developers in a positive atmosphere? Then join Studio BSD: roblox.com/My/Groups.aspx?gid=1013064 |
|
|
| Report Abuse |
|
|