Rounding always up (or based on sign) is statically biased, as the average of a list of numbers will allways tend to increase after you round them.
You are NOT allowed to use this "always up" method it in the S.I. (International System of Units, refer to section B7.1, read it here: http://www.hcsoft.net/lab/comohacer/redondeos/SI.png),
nor the ASTM standards in USA (stated on the D29 standard, a spanish explanation is here: http://www.astm.org/SNEWS/SPANISH/SPSO08/datapoints_spso08.html)
or in any ISO or UNE standard, as they all refer to the S.I. for rounding.
So, in lots of technical environments, actual rounding schema is not usable.
In maths and the alike, included most SQL engines (http://www.w3schools.com/sql/sql_func_round.asp
) you always use the "even rule" (ANSI/IEEE Std 754-1985 standard for floating point artihmetic): in case of ending in 0.5, always round to the nearest EVEN number. 13.5 would round to 14 and -13.5 will round to -14 too.
Will it be possible to have a flag -or an optional third parameter- so the round() funtion uses the nicer "even rounding rule, IEEE 754 standard" instead of actual "positives up, negatives down"?
UPDATE: I forged a round procedure that works like I spected.
CREATE OR ALTER PROCEDURE ROUND_EVEN (
IMPORTE double precision,
DECI integer )
VALOR double precision )
declare variable Multi integer;
declare variable IntVal bigint;
Multi = Power(10, Deci);
Valor = Importe * Multi;
if ((Valor - Floor(Valor)) = 0.5) then begin
if (Mod (Ceil(Valor), 2) = 0) then
IntVal = Ceil(Valor);
IntVal = Floor(Valor);
end else begin
IntVal = round(Valor);
Valor = cast (IntVal as double precision)/Multi;