mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-24 22:40:11 +08:00

toNumber方法传入参数toFixedNumber并未生效 , toFixed(2) 为固定保存两位小数 , 此处PR修复了参数传入并生效问题 Signed-off-by: chillley <chillley@163.com>
33 lines
816 B
TypeScript
33 lines
816 B
TypeScript
import isObject from 'lodash/isObject'
|
|
|
|
export function isString(p: any): p is string {
|
|
return typeof p === 'string'
|
|
}
|
|
|
|
export function isNumber(p: any): p is number {
|
|
return typeof p === 'number'
|
|
}
|
|
|
|
export function isBoolean(p: any): p is boolean {
|
|
return typeof p === 'boolean'
|
|
}
|
|
|
|
export function isUndefined(p: any): p is undefined {
|
|
return typeof p === 'undefined'
|
|
}
|
|
|
|
export function isNull(p: any): p is null {
|
|
return p === null
|
|
}
|
|
|
|
export function isArray(p: any): p is [] {
|
|
return Array.isArray(p)
|
|
}
|
|
|
|
export const toNumber = (number: number | string, toFixedNumber: number = 2) => {
|
|
return isString(number) ? parseFloat(parseFloat(number).toFixed(toFixedNumber)) : number
|
|
}
|
|
|
|
export const toString = (str: any) => {
|
|
return isNumber(str) ? `${str}` : (isObject(str) ? JSON.stringify(str) : str)
|
|
} |