浮点字符串数浮动2位小数?

时间:2018-03-22 13:21:09

标签: python python-3.x

我有一个功能

renderText(param){
  return <Text style={{ fontWeight: 'bold' }}>{param}</Text>
}

render(){
  return (
    <View>{this.renderText("bar")}</View>
  )
}

有没有其他方法可以实现这个浮动结果?

1 个答案:

答案 0 :(得分:0)

您可以使用locale.atof,如this question所示,它抽象十进制标点符号和千位分隔符等内容:

import locale
locale.setlocale(locale.LC_ALL, 'pt_BR') # Set to the proper language/country

def float_():
    price_data = {}
    str_num = '3.505,32'
    price_data['price'] = locale.atof(str_num)
    price_data['currency'] = 'USD'
    return price_data