function UnformatNumber(number) {
    if (!number)
        number = 0;
    // make string..
    number = number + '';
    // remove 1000 sep
    while (number.indexOf('.') != -1) 
        number = number.replace('.', '');
    // change ',' to '.'
    number = number.replace(',', '.');
    return parseFloat(number);
}

function FormatNumber(number, precision) {
    if (!number) number = 0;
    var precision = precision == 0 || precision ? precision : 2;

    // make string..
    number = number + '';
    var minus = false;
    if (number.charAt(0) == '-') {
        minus = true;
        number = number.slice(1);
    }
    number = number.replace(',', '.');
    // round
    number = toFixed(number, precision);
    //Non numeric value
    if (number == 'NaN.NaN') return '0,00';
    // add 1000 sep
    var tmp = number.split(".");
    var c = '';
    for (var i = tmp[0].length; i != -1; i--) {
        c += tmp[0].charAt(i);
        if ((tmp[0].length - i) == 0 || i == 0)
            continue;
        if ((tmp[0].length - i) % 3 == 0)
            c += '.';
    }
    // reverse c
    c = c.split("").reverse().join("");
    if (minus)
        c = '-' + c;
    return precision == 0 ? c : c + ',' + tmp[1];
}

function toFixed(value, precision) {
    var precision = precision || 0, neg = value < 0, power = Math.pow(10,
            precision), value = Math.round(value * power), integral = String((neg ? Math.ceil
            : Math.floor)(value / power)), fraction = String((neg ? -value
            : value)
            % power), padding = new Array(Math.max(precision - fraction.length,
            0) + 1).join('0');
    if (neg && integral=="0") //problem with Math.floor and Math.ceil with result zero (lose sign)
        integral='-'+integral;
    return precision ? integral + '.' + padding + fraction : integral;
}

function QuantityFormat(number,precision){
	if (!number) number = 0;
    var precision = precision == 0 || precision ? precision : 2;
    // make string..
    number = number + '';
    var minus = false;
    if (number.charAt(0) == '-') {
        minus = true;
        number = number.slice(1);
    }
    number = number.replace(',', '.');
    // round
    number = toFixed(number, precision);
    //Non numeric value
    if (number == 'NaN.NaN') return '0.000000';
    if (number == 'Infinity') return '0.000000';
    // add 1000 sep
    var tmp = number.split(".");
    var c = '';
    for (var i = tmp[0].length; i != -1; i--) {
        c += tmp[0].charAt(i);
        if ((tmp[0].length - i) == 0 || i == 0)
            continue;
        if ((tmp[0].length - i) % 3 == 0)
            c += '';
    }
    // reverse c
    c = c.split("").reverse().join("");
    if (minus)
        c = '-' + c;
    return precision == 0 ? c : c + ',' + tmp[1];
}