/**
 * Created by chen on 2017/7/5.
 */

// Number.prototype.toDecimal = function (ADigit) {
//     return parseFloat(this.toFixed(ADigit));
// };

var  number_util = {
    isNumber : function (obj) {
        return obj === +obj;
    },
    checkNumberValue: function (editingText, decimal) {
        let value;
        if (decimal) {
            value = Number(editingText);
            if (number_util.isNumber(value)) {
                value = value.toDecimal(decimal);
            } else {
                value = null;
                alert('当前输入的数据类型不正确，请重新输入。');
            }
        } else {
            value = editingText;
        }
        return value;
    },
    roundToString:function(obj,decimal){
        let value;
        if(this.isNumber(obj)){
            value = scMathUtil.roundTo(obj,-decimal)
        }else {
            value = scMathUtil.roundTo(Number(obj),-decimal);
        }
        return value.toFixed(decimal);
    },
    isNum(thisValue){
        var regPos = /^\d+(\.\d+)?$/; //非负浮点数
        var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
        return (regPos.test(thisValue) || regNeg.test(thisValue));
    }
}
