|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 13 Jun 2016 08:38 PM |
Hundredths.
Matthew: "Scripting for ROBLOX intelligence? There is no intelligence in ROBLOX." Me: "LOL" |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|