美文网首页
2018-01-26

2018-01-26

作者: NOTEBOOK2 | 来源:发表于2018-01-26 16:53 被阅读0次

    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)
      }
    }
    

    相关文章

      网友评论

          本文标题:2018-01-26

          本文链接:https://www.haomeiwen.com/subject/alswaxtx.html