generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Rounding whole numbers

Previous Thread :: Next Thread 
PhantomVisual is not online. PhantomVisual
Joined: 08 Apr 2011
Total Posts: 2025
24 Mar 2017 02:50 PM
How would I round numbers like 986 to 1000?


Report Abuse
cntkillme is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
PhantomVisual is not online. PhantomVisual
Joined: 08 Apr 2011
Total Posts: 2025
24 Mar 2017 02:58 PM
Alright, thanks!


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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 is not online. 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
ASpoonfullOfSucrose is not online. ASpoonfullOfSucrose
Joined: 28 Oct 2015
Total Posts: 442
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 is not online. 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 is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Mar 2017 06:41 PM
Kill me
Report Abuse
KapKing47 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image