import DateUtil from "./DateUtil";
function completeDouble(num){
    if(num < 10){
        num = '0' + num;
    }
    return num;
}
template.defaults.imports.formatDate = function(timestampOrdate, format='YYYY-MM-DD hh:mm:ss'){
    return DateUtil.formatDate(timestampOrdate);
};
template.defaults.imports.stringify = function(data){
    return JSON.stringify(data);
};
template.defaults.imports.toFixed2 = function (val) {
    if(typeof val == 'string') {
        val = parseFloat(val);
    }
    let str = val.toString();
    str = str.toLowerCase();
    if(str && str.indexOf('.') >= 0) {
        str = str.split('.');
        if(str[1].length > 2) {
            val = val.toFixed(2);
            return val;
        }else {
            return val;
        }
    }else if(str && (str.indexOf('e') > 0)) {
        val = val.toFixed(2);
        return val;
    }else {
        return val
    }
};
template.defaults.imports.EnotationToNumber = function (val) {
    if(typeof val == 'string') {
        return val;
    }
    let str = val.toString();
    str = str.toLowerCase();
    if(str && str.indexOf('e') > 0) {
        let arr = str.split('e');
        let num = parseInt(arr[1]);
        if(num < 0) {
            num = 0 - num;
        }
        val = val.toFixed(num);
        return val;
    }else {
        return val;
    }
};