[DEV] Better rounding (forget math.round() !) 
7 comments29.01.12 03:56:35 am

39 kb, 318 Downloads
[DEV] Better rounding (forget math.round() !)
Developer Tool
Hey all!
I made this script for developers who don't like Lua's default inaccurate math.round(). Why? Because it fails!
Feature:
All description you need is on the picture.
In fact my small function corrects the math.round() whenever it returns a wrong value.
For example, math.round(2.3) returns you a 3.
How to use:
1. Add the whole part of the code to your script or add the file with dofile(better_rounding.lua)
2. Use round(2.3) instead math.round(2.3) !
Permissions:
There're no restrictions. Use the code how you want!
But please don't reupload it anywhere and say it's yours! (the code is very simple and you're just an idiot if you do that ;))
About:
Only 8 lines of code and 115 characters. Smallest script (function) I've ever made.
Developer Tool
Hey all!
I made this script for developers who don't like Lua's default inaccurate math.round(). Why? Because it fails!


All description you need is on the picture.
In fact my small function corrects the math.round() whenever it returns a wrong value.
For example, math.round(2.3) returns you a 3.
Quote:
math.round(2.1) => 3
math.round(2.7) => 3
My round() :
round(2.1) => 2
round(2.7) => 3
math.round(2.7) => 3
My round() :
round(2.1) => 2
round(2.7) => 3

1. Add the whole part of the code to your script or add the file with dofile(better_rounding.lua)
2. Use round(2.3) instead math.round(2.3) !


There're no restrictions. Use the code how you want!
But please don't reupload it anywhere and say it's yours! (the code is very simple and you're just an idiot if you do that ;))
About:
Only 8 lines of code and 115 characters. Smallest script (function) I've ever made.
edited 4×, last 29.01.12 04:00:21 am

Comments
7 comments



Log in!
You need to log in to be able to write comments!Log in
@
Apache uwu:
There're people who are better than someone
Should I also add your script to the archive?
@
DannyDeth:
Nice idea. Will make examples of it.

There're people who are better than someone

Should I also add your script to the archive?
@

Nice idea. Will make examples of it.

@
DannyDeth: numbers lesser than n.5 + 0.5 on math.floor will return n, but any numbers over n.5 +0.5 on math.floor will give n+1, so i think it is right lol.

@
Apache uwu:
No, it couldn't. That would just floor it to the lowest value, which is not what "rounding" a number does.
@VADemon:
Try modifying the math table:
Comes to mind.

No, it couldn't. That would just floor it to the lowest value, which is not what "rounding" a number does.
@VADemon:
Try modifying the math table:
Code:
1
math.round = round
Comes to mind.



