fixed amount 3
This commit is contained in:
@@ -5,20 +5,21 @@ export type ProductCashFeeSource = {
|
|||||||
cash_fee_sell_is_percent?: boolean | null
|
cash_fee_sell_is_percent?: boolean | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 5 => 5% ، 0.05 => 5% (اعشاری) */
|
/** 0.5 => 0.5% ، 5 => 5% — همیشه عدد درصد */
|
||||||
export function resolveFeePercentRatio(percentValue?: number | null) {
|
export function resolveCashFeePercentRatio(percentValue?: number | null) {
|
||||||
const offset = Number(percentValue ?? 0)
|
const offset = Number(percentValue ?? 0)
|
||||||
if (!offset) {
|
if (!offset || !Number.isFinite(offset)) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Math.abs(offset) > 0 && Math.abs(offset) < 1) {
|
|
||||||
return offset
|
|
||||||
}
|
|
||||||
|
|
||||||
return offset / 100
|
return offset / 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated از resolveCashFeePercentRatio استفاده کنید */
|
||||||
|
export function resolveFeePercentRatio(percentValue?: number | null) {
|
||||||
|
return resolveCashFeePercentRatio(percentValue)
|
||||||
|
}
|
||||||
|
|
||||||
export function resolveProductCashFeeRial(
|
export function resolveProductCashFeeRial(
|
||||||
feeValue: number | null | undefined,
|
feeValue: number | null | undefined,
|
||||||
isPercent: boolean | null | undefined,
|
isPercent: boolean | null | undefined,
|
||||||
@@ -38,7 +39,7 @@ export function resolveProductCashFeeRial(
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math.round(Math.abs(base * resolveFeePercentRatio(raw)))
|
return Math.round(Math.abs(base * resolveCashFeePercentRatio(raw)))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveProductCashFeeBuyRial(product: ProductCashFeeSource, basePriceRial: number) {
|
export function resolveProductCashFeeBuyRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||||
@@ -67,7 +68,8 @@ export function formatProductCashFeeLabel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isPercent) {
|
if (isPercent) {
|
||||||
return `${raw}%`
|
const text = Number.isInteger(raw) ? String(raw) : String(parseFloat(raw.toFixed(4)))
|
||||||
|
return `${text}%`
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${raw} ریال`
|
return `${raw} ریال`
|
||||||
|
|||||||
Reference in New Issue
Block a user