22 lines
623 B
TypeScript
22 lines
623 B
TypeScript
/**
|
|
* 显示价格把分转换到元
|
|
* @param price
|
|
* @returns
|
|
*/
|
|
export function displayPrice(price: any, suffix: string = "元", fixed = 2) {
|
|
if (typeof price === "undefined") return "0.00" + suffix
|
|
const parsedNumber = typeof price === "string" ? parseFloat(price) : price
|
|
return (parsedNumber / 100.0).toFixed(fixed) + suffix
|
|
}
|
|
|
|
/**
|
|
* 把显示价格改为分
|
|
* @param price
|
|
* @returns
|
|
*/
|
|
export const storePrice = (num: number | string | undefined) => {
|
|
if (typeof num === "undefined") return 0
|
|
const parsedNumber = typeof num === "string" ? parseFloat(num) : num
|
|
return Math.round(parsedNumber * 100)
|
|
}
|