统一金额分制重构

This commit is contained in:
yml
2026-06-09 19:04:11 +08:00
parent 87673288ef
commit 5cd3ead4bd
69 changed files with 886 additions and 1277 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import type { Listing } from '@/features/listings/api/listings'
import { centToYuan } from '@/shared/utils/money'
export interface ListingDisplayChip {
label: string
@@ -41,7 +42,7 @@ export function formatHafCoinM(amountWan: number) {
}
export function getListingDisplayPrice(item: Listing) {
return Number(item.price || 0)
return centToYuan(item.price_cent)
}
export function getListingRentPrice(item: Listing) {
+12 -5
View File
@@ -40,12 +40,19 @@ export function centToYuan(cent: number | undefined | null): number {
}
/**
* 分转(四舍五入到0.1元)
* @example centToJiao(12345) -> 123.5
* @example centToJiao(12344) -> 123.4
* 分转展示用元(四舍五入到0.1元)
* @example centToDisplayYuan(12345) -> 123.5
* @example centToDisplayYuan(12344) -> 123.4
*/
export function centToDisplayYuan(cent: number | undefined | null): number {
return roundMoney(centToYuan(cent))
}
/**
* @deprecated 使用 centToDisplayYuan。保留导出避免旧导入立刻失效。
*/
export function centToJiao(cent: number | undefined | null): number {
return Math.round(Number(cent || 0) / 10) / 10
return centToDisplayYuan(cent)
}
/**
@@ -54,7 +61,7 @@ export function centToJiao(cent: number | undefined | null): number {
* @example formatCent(12344) -> "123.4"
*/
export function formatCent(cent: number | undefined | null): string {
return centToJiao(cent).toFixed(1)
return centToDisplayYuan(cent).toFixed(1)
}
/**