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 numbers (to integers OR decimals)

Previous Thread :: Next Thread 
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
31 Mar 2014 11:52 AM
I made my own rounding function after finding out Lua only has math.floor and math.ceil

Here is the function with some example code for you to test it with idk


function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end


round_nums = {
round(0.9345, 3); --> 0.935
round(0.2); --> 0
round(0.49); --> 0
round(0.5); --> 1
}

for k,v in pairs(round_nums) do
print(v)
end
print("end of test")
Report Abuse
suremark is not online. suremark
Joined: 13 Nov 2007
Total Posts: 6315
31 Mar 2014 05:13 PM
Funny, yours looks very similar to mine:

function roundf(n, dec)
    dec = dec and 10^(math.floor(dec + 0.5)) or 1
    return math.floor(n * dec + 0.5)/dec
end

Anyhow please only post something if it is notable and worthwhile. Anything with less than half an hour of work (let alone five minutes) put into it is just adding to the already-huge spam pile.
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