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
 

Float Numbers

Previous Thread :: Next Thread 
spaceranger7 is not online. spaceranger7
Joined: 18 Jul 2010
Total Posts: 347
21 Jun 2015 11:56 PM
How do I use math.floor or math.ceil to successfully round a float number (such as a transparency value) accurately? The problem I face is that the numbers sometimes round down while others round up.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Jun 2015 11:59 PM
math.floor(num + .5)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
22 Jun 2015 12:00 AM
function _G.round(n)
n = tostring(n)
local decimal = string.find(n, ".", 1, true)
return n:sub(0, decimal + 1)
end

print(_G.round(50.5132423)) -- Will print "50.5"
print(_G.round(10.43)) -- Will print "10.4"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
22 Jun 2015 12:01 AM
that is gross, please don't use string manip. to do number stuff.
If he want to round to the 1/10's place, just do (math.floor((num * 10) + .5) / 10)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
22 Jun 2015 12:03 AM
cnt. Wasn't my script. I just found a free model :)
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