How do i update text input value to use currency format

问题: This is my code : onChangeTextPrice(value) { const newPrice = parseInt(value, 10).toLocaleString(['ban', 'id']); return this.setState({ price: formatted }); } If I...

问题:

This is my code :

onChangeTextPrice(value) {
  const newPrice = parseInt(value, 10).toLocaleString(['ban', 'id']);
  return this.setState({ price: formatted });
}

If I console.log(newPrice), it will give me the format, for example : 10.000.000

but for some reason react native textinput doesn't use this value instead it show 10000000.

but if I change TextInput value like this:

<TextInput
   keyboardType="numeric"
   value={'10.000.000'}
   multiline={false}
   underlineColorAndroid="transparent"
   onChange={val => this.onChangeTextPrice(val)}

It works. Why is that ?


回答1:

You might wanna use one of the following packages in order to achieve simple/complex input maskings.

github.com/benhurott/react-native-masked-text

github.com/react-native-community/react-native-text-input-mask

A nice tutorial can be found here

  • 发表于 2018-07-11 03:05
  • 阅读 ( 269 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除