Overview line 300
<Input
name="quantity"
label="Availiable Quantity"
disabled
value={(_: any, { qtyOnShelf, qtyStockroom }: any) => {
const a = parseFloat(qtyOnShelf)
const b = parseFloat(qtyStockroom)
if (Number.isNaN(a) || Number.isNaN(b)) {
return "0.00"
} else {
return (a + b).toFixed(2)
}
}}
/>
utils/formatter.ts
export const currency = (input: string | number) => {
const price = typeof input === "number" ?
input : parseFloat(input)
return Number.isNaN(price) ? "" : `$${price.toFixed(2)}`
}
formatter和getter两步处理输入:
export const currency = (input: string | number) => {
const price = typeof input === "number" ? input : parseFloat(input)
return Number.isNaN(price) ? "" : `$${price.toFixed(2)}`
}
// step 1 any----string
// step 2 string----number
export const currency {
formatter: (input: any) => {
const price = typeof input === "number" ? input : parseFloat(input)
return Number.isNaN(price) ? "" : `$${price.toFixed(2)}`
}
getter: (input: string) => {
input.replace(/$/g, "")
return parseFloat(input)
}
}
网友评论