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: How do I eliminate decimals?

Previous Thread :: Next Thread 
Card_Player is not online. Card_Player
Joined: 22 Mar 2016
Total Posts: 73
06 Sep 2016 07:49 PM
this is for an ingame currency system with withdraw/deposit.

I would use math.floor but they can keep depositing 0.5 and getting 1 for it, and generate cash.


Is there a way i can somehow make it use ONLY whole numbers?

ty
Report Abuse
Xsitsu is online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
06 Sep 2016 07:52 PM
Just don't let them deposit anything that isn't a whole number.

if (math.floor(number) ~= number) then
error("you can't deposite non whole numbers!")
end
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
06 Sep 2016 07:52 PM
Ya you can check to see if a number is a whole number with this:


function checkWhole(input)
return input % 1 == 0
end

that'll return true for numbers like 1 or 2, but false for 0.5
Report Abuse
L2000 is not online. L2000
Joined: 03 Apr 2008
Total Posts: 77448
06 Sep 2016 07:57 PM
How are you doing your math.floor? Its probably in the wrong place if its not working.

Alternatively, you could use string.format (I'm assuming Lua has it) to grab the whole number chunk of the number and add that


If you're seeing this post, it means I'm either dead (leaving behind a very fabulous looking corpse) or my soul has been captured by pixies!
Report Abuse
rapmilo is not online. rapmilo
Joined: 16 Aug 2011
Total Posts: 69
06 Sep 2016 07:58 PM
Well if you want to round the number just try this: function round(number) if (number - (number % 0.1)) - (number - (number % 1)) < 0.5 then number = number - (number % 1) else number = (number - (number % 1)) + 1 end Honestly these are the few times where Lua lacking the equivalent of a int variable in Java is inconvenient. If you want to test the code...just type print(round(X)) where X is ### ###### of your choosing. Check if the rounding is correct and you're done.
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
06 Sep 2016 09:01 PM
string.format("%.2",123.239)
Report Abuse
RemasteredBox is not online. RemasteredBox
Joined: 19 Jun 2016
Total Posts: 2140
06 Sep 2016 09:59 PM
local wholeNumber, decimal = math.modf(Number)
Report Abuse
rapmilo is not online. rapmilo
Joined: 16 Aug 2011
Total Posts: 69
07 Sep 2016 08:05 PM
Here's a neater version:
function round(number)
if (number - (number % 0.1)) - (number - (number % 1)) < 0.5
then number = number - (number % 1)
else number = (number - (number % 1)) + 1
end
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
07 Sep 2016 08:09 PM
math.floor(num)
That's all you need. The reason why 0.5 went to 1 is probably because you added 0.5 to num or you used math.ceil
Report Abuse
killerbot29003 is online. killerbot29003
Joined: 04 Oct 2014
Total Posts: 3054
07 Sep 2016 08:18 PM
or maybe

thing = 123223233.222

print(tostring(thing):sub(1,math.max(tostring(thing):find("%.")) - 1))



not recommended and you should use math.floor/math.ceil


This siggy is copyrighted ©
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