src/helper.js
function (value, precision, mode) {
            /* jshint -W016 */
            /* jshint -W018 */

            // Helper variables
            var base, floorNum, isHalf, sign;

            // Making sure precision is integer
            precision |= 0;
            base = Math.pow(10, precision);
            value *= base;

            // Sign of the number
            sign     = (value > 0) | -(value < 0);
            isHalf   = value % 1 === 0.5 * sign;
            floorNum = Math.floor(value);

            if (isHalf) {
                mode = mode ? mode.toUpperCase() : "DEFAULT";
                switch (mode) {
                    case "DOWN":
                        // Rounds .5 toward zero
                        value = floorNum + (sign < 0);
                        break;
                    case "EVEN":
                        // Rouds .5 towards the next even integer
                        value = floorNum + (floorNum % 2 * sign);
                        break;
                    case "ODD":
                        // Rounds .5 towards the next odd integer
                        value = floorNum + !(floorNum % 2);
                        break;
                    default:
                        // Rounds .5 away from zero
                        value = floorNum + (sign > 0);
                }
            }

            return (isHalf ? value : Math.round(value)) / base;
            /* jshint +W016 */
            /* jshint +W018 */
        }
function (value, precision, mode) {
            /* jshint -W016 */
            /* jshint -W018 */

            // Helper variables
            var base, floorNum, isHalf, sign;

            // Making sure precision is integer
            precision |= 0;
            base = Math.pow(10, precision);
            value *= base;

            // Sign of the number
            sign     = (value > 0) | -(value < 0);
            isHalf   = value % 1 === 0.5 * sign;
            floorNum = Math.floor(value);

            if (isHalf) {
                mode = mode ? mode.toUpperCase() : "DEFAULT";
                switch (mode) {
                    case "DOWN":
                        // Rounds .5 toward zero
                        value = floorNum + (sign < 0);
                        break;
                    case "EVEN":
                        // Rouds .5 towards the next even integer
                        value = floorNum + (floorNum % 2 * sign);
                        break;
                    case "ODD":
                        // Rounds .5 towards the next odd integer
                        value = floorNum + !(floorNum % 2);
                        break;
                    default:
                        // Rounds .5 away from zero
                        value = floorNum + (sign > 0);
                }
            }

            return (isHalf ? value : Math.round(value)) / base;
            /* jshint +W016 */
            /* jshint +W018 */
        }
function ( value , precision , mode ) { /* jshint -W016 */ /* jshint -W018 */ // Helper variables var base , floorNum , isHalf , sign ; // Making sure precision is integer precision |= 0 ; base = Math . pow ( 10 , precision ) ; value *= base ; // Sign of the number sign = ( value > 0 ) | - ( value < 0 ) ; isHalf = value % 1 === 0.5 * sign ; floorNum = Math . floor ( value ) ; if ( isHalf ) { mode = mode ? mode . toUpperCase ( ) : "DEFAULT" ; switch ( mode ) { case "DOWN" : // Rounds .5 toward zero value = floorNum + ( sign < 0 ) ; break ; case "EVEN" : // Rouds .5 towards the next even integer value = floorNum + ( floorNum % 2 * sign ) ; break ; case "ODD" : // Rounds .5 towards the next odd integer value = floorNum + ! ( floorNum % 2 ) ; break ; default : // Rounds .5 away from zero value = floorNum + ( sign > 0 ) ; } } return ( isHalf ? value : Math . round ( value ) ) / base ; /* jshint +W016 */ /* jshint +W018 */ }
Rounds a float

@link http://php.net/manual/en/function.round.php
@link http://phpjs.org/functions/round/

@param value
@param precision
@param mode
@returns {number}
Rounds a float