|
| 24 Mar 2017 02:50 PM |
How would I round numbers like 986 to 1000?
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Mar 2017 02:54 PM |
Divide by 1000, add .5, floor, multiply by 1ooo
986/1ooo= .986 + .5 = 1.whatever Rounded down = 1 * 1ooo = 1ooo |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 02:57 PM |
| local function round( num, place ) if place then local plc = ## # ##### return math.floor( num * plc + 0.5 ) / plc end return math.floor( num + 0.5 ) end use integers from inf to -inf to choose how many places |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 02:57 PM |
| local function round( num, place ) if place then local plac = ## # ##### return math.floor( num * plac + 0.5 ) / plac end return math.floor( num + 0.5 ) end use integers from inf to -inf to choose how many places or you can do it his way if you only want to round specifically to the ks |
|
|
| Report Abuse |
|
|
| |
|
|
| 24 Mar 2017 02:58 PM |
local function round( num, pl ) if pl then local plac = ____ return math.floor( num * plac + 0.5 ) / plac end return math.floor( num + 0.5 ) end
use integers from inf to -inf to choose how many places or you can do it his way if you only want to round specifically to the ks
my god the roblox filter
the ____ is TEN TO THE POWER OF PL |
|
|
| Report Abuse |
|
|
Venetrix
|
  |
| Joined: 10 Feb 2012 |
| Total Posts: 402 |
|
|
| 24 Mar 2017 02:59 PM |
function round(number, DeciPlaces) local x = 10^(DeciPlaces or 0) return math.floor(num * x + 0.5) / x end
I post stuff for no reason - 5,077 |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 03:01 PM |
function Round(num, numDecimalPlaces) --To nearest ten = -1 --To nearest hundred = -2 --To nearest thousand = -3 local mult = 10^(numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Mar 2017 06:40 PM |
| i win ... local floor, #### = math.floor, ######### function round(num, idp, base, towards_zero) idp = idp or 0 base = base or 10 local mult = base^idp if towards_zero and num >= 0 then return ################# - 0.5)/base^idp end return floor(num*base^idp + 0.5)/base^idp end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 24 Mar 2017 06:54 PM |
local function round(Number, RoundTo) Number = Number + (RoundTo * .5) return Number - (Number % RoundTo) end
This should work.
|
|
|
| Report Abuse |
|
|