// Namespace for fixed point number functions
FixedPointNumber = {}

// Invoke as FixedPointNumber.from('1234,56')
FixedPointNumber.from = function(str){
    var regex, matches, value;
    var str = String(str);
    if(str.indexOf(".") != -1) {
        regex = /^([\d]+)(\.)([\d]+)$/;
        if (matches = regex.exec(str)) {
            if (matches[3].length < 2) {
                value = matches[1] + matches[3] + "0";
            } else if (matches[3].length > 2) {
                
                var roundUp = Math.round('0.'+ matches[3].substr(2,matches[3].length));
                roundUp = parseInt(matches[3].substr(0,2)) + roundUp;
                value = matches[1] + roundUp;
                //value = matches[1] + matches[3].substr(0,2);
            } else {
                value = matches[1] + matches[3];
            }
        } else {
            value = 0;
        }
    } else {
        regex = /^[\d]+$/;
        if(matches = regex.exec(str)) {
            value = str + "00";
        } else {
            value = 0;
        }
    }
    
    return parseInt(value, 10);
}

// Invoke as FixedPointNumber.to('123456')
FixedPointNumber.to = function(str, decimalPlaces) {
    var prefix, suffix;
    
    // Convert integer to string
    str += '';
    
    if (decimalPlaces == undefined) {
        decimalPlaces = 2;
    }
    
    if (str.length > decimalPlaces) {
        prefix = str.slice(0, -decimalPlaces);
        suffix = str.slice(str.length - decimalPlaces);
    } else if(str.length == decimalPlaces) {
        prefix = "0";
        suffix = str;
    } else if(str.length == 0) {
        prefix = "0";
        suffix = "00";
    } else {
        prefix = "0";
        suffix = "0"+str;
    }
    
    return prefix + "." + suffix;
}

        