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
 

Re: Getting part of a number

Previous Thread :: Next Thread 
sharpchain1 is not online. sharpchain1
Joined: 05 Aug 2013
Total Posts: 1009
04 May 2015 07:45 PM
Hey guys so I have a script and it involves dividing and so when I divide the numbers I get a decimal and so I only want the whole number how do I do this

Example
5.32 I want to get the 5 separately from the .32
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
04 May 2015 07:52 PM
I'm sure there are some othery methods but I like to keep it simple so you can just use a rounder.

function _G.round(val, decimal)
if (decimal) then
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
else
return math.floor(val+0.5)
end
end

print(_G.round(100.32, 0)) --This will print the number of decimals you want so,

Output:
100


print(_G.round(100.55,1)) --this will round to the first decimal place
>
100.6
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
04 May 2015 07:54 PM
You can use math.floor or math.modf

math.modf(2.5) --> 2, 0.5
math.floor(2.5) --> 2
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
04 May 2015 07:57 PM
or that ^ l0l
Report Abuse
sharpchain1 is not online. sharpchain1
Joined: 05 Aug 2013
Total Posts: 1009
04 May 2015 08:29 PM
Ok thx helped a lot guys
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