typescript保留小数位和类型判断

let num: number = 123456789.789; let str: string = num.toFixed(2); 还是可以

//1. typeof
typeof padding === "number";
typeof padding === "string";
typeof obj === "object";

//2. instanceof
if(padder instanceof User){
    
}
//3. constructor.name
if(this.constructor.name=="User"){
   
}


    /**
     * 校验字符串是否是数值(包含小数与负数)
     * 示例:
     * false : . 1. 1sr -  12. -12.
     * true: -12 -12.0 -12.056 12 12.0 12.056
     *
     * @param str 需要校验的字符串
     * @return false :不是数值 true:是数值
     */
    public Boolean checkNumber(String str) {
        String regex = "-[0-9]+(.[0-9]+)?|[0-9]+(.[0-9]+)?";
        if (str == null || !str.matches(regex)) {
            return false;
        }
        return true;
    }