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: Rounding off a number

Previous Thread :: Next Thread 
CeaselessSoul is not online. CeaselessSoul
Joined: 03 Jul 2012
Total Posts: 7506
13 Jun 2016 08:10 PM
local number = 5.02;
number = number - (number % 0.001);
print(number);
--> 5.019

0.001 is subtracted from "number". Now, let's say number is 5.0006, it will round fine. Why does this happen? Why is 0.001 being subtracted, and how can I fix it without being hacky?


Matthew: "Scripting for ROBLOX intelligence? There is no intelligence in ROBLOX." Me: "LOL"
Report Abuse
0Dan is not online. 0Dan
Joined: 22 Oct 2009
Total Posts: 2552
13 Jun 2016 08:25 PM
Not sure whats going on, but you could use this to found the number:
local number = 5.02
print(math.floor(number+.5))


Report Abuse
CeaselessSoul is not online. CeaselessSoul
Joined: 03 Jul 2012
Total Posts: 7506
13 Jun 2016 08:29 PM
I know that, but I want it rounded off to a decimal, not a whole number.


Matthew: "Scripting for ROBLOX intelligence? There is no intelligence in ROBLOX." Me: "LOL"
Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
13 Jun 2016 08:32 PM
I'm confused on what you want to do...you want to simply round it?

5.02 modulus 0.001 will not come out even

function Round(number)
if number - math.floor(number) < 0.5 then
return math.floor(number)
else
return math.ceil(number)
end
end

Formerly ToxicDominator - add 17,509 posts | :(){:|:&};:
Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
13 Jun 2016 08:32 PM
oh I didn't see your last reply ignore that

Formerly ToxicDominator - add 17,509 posts | :(){:|:&};:
Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
13 Jun 2016 08:34 PM
to which place value do you want to round to

Formerly ToxicDominator - add 17,509 posts | :(){:|:&};:
Report Abuse
CeaselessSoul is not online. CeaselessSoul
Joined: 03 Jul 2012
Total Posts: 7506
13 Jun 2016 08:38 PM
Hundredths.


Matthew: "Scripting for ROBLOX intelligence? There is no intelligence in ROBLOX." Me: "LOL"
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
13 Jun 2016 08:41 PM
local function Round(Number, Places)
return math.floor(Number*10^Places+0.5)/10^Places
end
Report Abuse
ray_1 is not online. ray_1
Joined: 18 Feb 2011
Total Posts: 464
13 Jun 2016 08:41 PM
function round(x,place)
local a = 10^place
return math.floor(x*a+.5)/a
end
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
13 Jun 2016 08:57 PM
inb4imadeamistkae

local number = 5.02534;
local remainder = number % 0.0001

if remainder >= 0.00005 then
number = number - remainder + 0.0001
end
Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
13 Jun 2016 08:58 PM
idk if OP wants it to round it to the nearest hundredths or just take off everything up to the hundredths

Formerly ToxicDominator - add 17,509 posts | :(){:|:&};:
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