/** * Objeto que contiene diversas funciones */ function JUtil() { this.roundOff = JUtilRoundOff; } /** * Redondea y formatea un número en base * a la precisión * @param (double) value Número a formatear * @param (int) precision Número de decimales */ function JUtilRoundOff(value, precision) { value = "" + value //convert value to string precision = parseInt(precision); var whole = "" + Math.round(value * Math.pow(10, precision)); if ( precision == 0) return whole; var decPoint = whole.length - precision; if(decPoint != 0) { result = whole.substring(0, decPoint); result += ","; result += whole.substring(decPoint, whole.length); if (result==",0") result="0,00"; } else { result = "0,"+whole; } return result; } jUtil = new JUtil();