Dateien

> > CS2D > Lua Scripts > [DEV] Better rounding (forget math.round() !)
DateiübersichtCS2D-ÜbersichtLua Scripts-Übersicht

Englisch [DEV] Better rounding (forget math.round() !) >

7 Kommentare39 kb, 452 Downloads

alt [DEV] Better rounding (forget math.round() !)

VADemon
User Off Offline

[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.
Zitat
math.round(2.1) => 3
math.round(2.7) => 3

My round() :
round(2.1) => 2
round(2.7) => 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.
4× editiert, zuletzt 29.01.12 04:00:21
Zugelassen von GeoB99

Download Download

39 kb, 452 Downloads

Kommentare

7 Kommentare
Zum Anfang Vorherige 1 Nächste Zum Anfang

Logge dich ein!

Du musst dich einloggen, um selber Kommentare verfassen zu können!Einloggen

alt

VADemon
User Off Offline

@user Apache uwu:
There're people who are better than someone

Should I also add your script to the archive?

@user DannyDeth:
Nice idea. Will make examples of it.

alt

DannyDeth
User Off Offline

Aah, never thought of that! Complete geniuses, both of you.

alt

DarkLight66
User Off Offline

@user 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.
Ich mag es!

alt

DannyDeth
User Off Offline

@user 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:
1
math.round = round
Comes to mind.

alt

Apache uwu
User Off Offline

This could just be 3 lines:

1
2
3
function round(a)
	return math.floor(a+0.5)
end

alt

KenVo
User Off Offline

Short but useful
Ich mag es!
Zum Anfang Vorherige 1 Nächste Zum Anfang