34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
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
|
|
}
|
|
|
|
export function displayYuanToYuan(price: any, suffix: string = "元", fixed = 2) {
|
|
if (typeof price === "undefined") return "0.00" + suffix
|
|
const parsedNumber = typeof price === "string" ? parseFloat(price) : price
|
|
return parsedNumber.toFixed(fixed) + suffix
|
|
}
|
|
|
|
export function displayWeight(price: any, fixed = 2) {
|
|
if (typeof price === "undefined") return "0"
|
|
const parsedNumber = typeof price === "string" ? parseFloat(price) : price
|
|
return parsedNumber.toFixed(fixed)
|
|
}
|
|
|
|
/**
|
|
* 把显示价格改为分
|
|
* @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)
|
|
}
|