我正在使用 react-table包及其表。
在表格props列中,我提交了对象,因为它的格式正确。
Header: 'Charter',
columns: [
{
Header: 'Title',
accessor: 'charter_title',
style: {
textAlign: 'center'
}
}
]
}
我想做的是将此列值格式化为货币
i.e. 10000.53 would be come 10,000.53
i.e. 1230000.123 would be come 1,230,000.123
是否react-table给你机会做这种格式化?
最佳答案
我发现 Cell 属性定义了每个单元格的输出。这是一些工作代码。您可以提供自定义函数来根据需要格式化每个单元格的值。
Header: 'Charter',
columns: [
{
Header: 'Title',
accessor: 'charter_title',
style: {
textAlign: 'center'
},
// provide custom function to format props
Cell: props => <div> toCurrency(props.value) </div>
}
]
}
我的自定义函数是:
function toCurrency(numberString) {
let number = parseFloat(numberString);
return number.toLocaleString('USD');
}
关于javascript - react 表包 : formatting float as currency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48704269/