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 » Scripting Helpers
Home Search
 

Re: Number Rounding

Previous Thread :: Next Thread 
wazup07 is not online. wazup07
Joined: 17 Oct 2009
Total Posts: 313
04 Aug 2013 06:44 PM
local f = I.Value*(1+.01)^Time


What I have here is an equation that results in an exponential growth. My problem though, is that this will output numbers with long strings of decimals. Is there any way to round the output, f, to the nearest whole number and then use that elsewhere? Thanks.
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
04 Aug 2013 06:47 PM
f = math.floor(f + .5)
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
04 Aug 2013 06:47 PM
there is probably a better way but here is how u could do it

local round = 1000
num = math.floor(num *round+.5)/round


change round by multiplying ten or dividing ten to change amt decimal points
Report Abuse
wazup07 is not online. wazup07
Joined: 17 Oct 2009
Total Posts: 313
04 Aug 2013 06:59 PM
Great thanks! adark's version worked out just fine, but i'll keep your method in mind.
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
04 Aug 2013 07:36 PM
Yeah his method is a lot better but you can keep some decimal places with mine if you choose to
Report Abuse
wazup07 is not online. wazup07
Joined: 17 Oct 2009
Total Posts: 313
04 Aug 2013 09:14 PM
Another question, is it posible to detect if a number is a whole number? For instance, if I were to add say 0.1 to 1 during a repeated loop, is there a way to detect when that number reaches a whole number? I don't mean like

if Number == 2 then

because I won't always have that exact value. Is something like this possible?
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
05 Aug 2013 11:11 AM
if Number == math.floor(Number + .5) then

Of course, this will most likely never run because floating point imprecision.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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