English 中文(简体)
如何从反应编号图书馆获得价值?
原标题:How to get value as number from react-number-format library?

我正在使用反应编号格式图书馆,以对用户的投入进行格式化。 但是,出于某种原因,在我节省数据时,这些投入正被保存为示意图而不是编号。 这一违约行为吗? 如果是的话,我怎么能够改变序号,以删除所有特性(例如,美元、ma等)的编号,从而节省了这种格式的插图?

This is how I am using it. npm package https://www.npmjs.com/package/react-number-format

               <NumberFormat
                    thousandSeparator={true}
                    prefix={"$"}
                    decimalScale={2}
                    fixedDecimalScale
                    disabled={isDisabled}
                 />
问题回答

You can use react-number-format s onValueChange prop to get the floatValue which is of type number.

可以这样使用:

  <NumberFormat
    {...someProps}
    onValueChange={(values) => {
      const {formattedValue, value, floatValue} = values;
      // do something with floatValue
    }}
  />

参考:

格式 价值:23 234 235.56 美元,在采用格式后

value: 23234235.56 , //non formatted value as numeric string 23234235.56, if you are setting this value to state make sure to pass isNumericString prop to true

floatValue: 23234235.56 //floating point representation. For big numbers it can have exponential syntax

See https://www.npmjs.com/package/react-number-format#values-object for more information.

页: 1 出口职能:

import { numericFormatter } from "react-number-format";
...
///value = 1234567.4
const t = numericFormatter(1234567.4, {thousandSeparator: true, decimalScale: 0});
/// t will be 1,234,567

这样,你也可以确定价值:

 <NumberFormat
{...someProps}
onValueChange={({floatValue}) => {
 return setState(floatValue);
}}/>

Im 使用反应堆照相

<Controller
  name={name}
  rules={rules}
  control={control}
  render={({ field: { value, onChange }, fieldState: { error } }) => (
      <NumericFormat
        value={value}
        onValueChange={(values) => {
          onChange(values.floatValue)
        }} />
>




相关问题
How to use one react app into another react app?

I have two react apps, parent app and child app. and child app have an hash router. I have build the child app using npm run build, It creates build folder. That build folder moved into inside the ...

how to get selected value in Ant Design

I want to print the selected value, and below is my option list: const vesselName = [ { value: 0 , label: ALBIDDA , }, { value: 1 , label: ALRUMEILA , }, { value: 2 ,...

How to add a <br> tag in reactjs between two strings?

I am using react. I want to add a line break <br> between strings No results and Please try another search term. . I have tried No results.<br>Please try another search term. but ...

热门标签