Javascript react native中的货币格式设置

Javascript react native中的货币格式设置,javascript,react-native,Javascript,React Native,我有一个简单的设置,可以使用数字js格式化输入到TextInput字段中的货币值。 使用onChangeText我正在设置输入的值并以这种方式格式化它 handleValue(value){ let amount = numeral(value).format('0,0[.]00') // set amount } 但出于某种原因,我们一直在删除自己。有办法解决这个问题吗?这对我很有用 小数点位于正确的位置 import React, { useState } from 'react'; i

我有一个简单的设置,可以使用数字js格式化输入到
TextInput
字段中的货币值。 使用
onChangeText
我正在设置输入的值并以这种方式格式化它

handleValue(value){
let amount = numeral(value).format('0,0[.]00')
// set amount 
}
但出于某种原因,我们一直在删除自己。有办法解决这个问题吗?

这对我很有用 小数点位于正确的位置

import React, { useState } from 'react';
import { Text, View, StyleSheet, TextInput } from 'react-native';

import numeral from 'numeral';

export default function App() {
  const [value, setValue] = useState('');
  const styles = StyleSheet.create({
    container: {
      flex: 1,
      justifyContent: 'center',
      backgroundColor: '#ecf0f1',

    },
  });
  
  const handleValue = (value) => {
    let amount = numeral(value).format('0,0[.]00');
    setValue(amount);
  };

  return (
    <View style={styles.container}>
      <TextInput
        onChangeText={(value) => handleValue(value)}
        style={{
          height: 40,
          width: 280,
          backgroundColor: 'white',
          borderWidth: 1,
          borderRadius: 4,
          alignSelf: 'center',
          paddingLeft: 15,
        }}
        value={value}
      />
    </View>
  );
}
import React,{useState}来自“React”;
从“react native”导入{Text,View,StyleSheet,TextInput};
从“数字”中导入数字;
导出默认函数App(){
const[value,setValue]=使用状态(“”);
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
背景颜色:“#ecf0f1”,
},
});
常量handleValue=(值)=>{
let amount=数字(值).format('0,0[.]00');
设定值(金额);
};
返回(
handleValue(值)}
风格={{
身高:40,
宽度:280,
背景颜色:“白色”,
边框宽度:1,
边界半径:4,
对齐自我:“中心”,
paddingLeft:15,
}}
value={value}
/>
);
}