Javascript 如何使用BootstrapVue将值格式化为货币?
我需要使用引导vue格式化程序(b表-字段)将值格式化为货币 我目前的尝试:Javascript 如何使用BootstrapVue将值格式化为货币?,javascript,vue.js,Javascript,Vue.js,我需要使用引导vue格式化程序(b表-字段)将值格式化为货币 我目前的尝试: fields: [ { key: 'value', label: 'value(R$)', sortable: true, formatter: (value, key, item) => { return Number(item.value).toLocaleString('pt-BR', { style: 'decimal', c
fields: [
{ key: 'value', label: 'value(R$)', sortable: true,
formatter: (value, key, item) => {
return Number(item.value).toLocaleString('pt-BR', {
style: 'decimal', currency: 'BRL'
})
}
},
]
我需要以某种方式格式化这些值我从后端(axios)获得的
可以帮助我吗?要使用
toLocaleString
将数字格式化为货币,您需要使用样式:“货币”
选项
您可以阅读有关toLocaleString
的更多信息。
如果您向下滚动到示例,并继续向下滚动到使用选项的部分,您将看到样式的两个示例:“货币”
选项。这就是我找到信息的地方
有关不同的选项,还可以参考“参数”部分
请注意,这不会进行任何货币转换。
请参阅下面的代码片段
newvue({
el:“#应用程序”,
数据(){
返回{
项目:[
{value:123.45},
{value:23},
{值:12.6}
],
字段:[
{key:'value',label:'value(R$)',可排序:true,
格式化程序:(值、键、项)=>value.toLocaleString('pt-BR',{style:'currency',currency:'BRL'})
},
]
}
}
})
我也可以这样做:
{ key: 'value', label: 'value(R$)', sortable: true,
formatter: (value, key, item) => {
return Number(item.value/100).toLocaleString('pt-BR', {minimumFractionDigits: 2, style: 'decimal', currency: 'BRL'})
}
},
ToLocalString对我不起作用,这是一个可能的解决方案:
formatter: (value, key, item) => {
let formatter = new Intl.NumberFormat("es-ES", {
style: "currency",
currency: "EUR",
minimumFractionDigits: 2
});
return formatter.format(value);
}
谢谢。您当前的代码无法使用的是什么?@Baumannzone您在寻找什么文档Bootstrap Vue
或fortoLocaleString
?两者都是:D我认为Bootstrap Vue有一个localeString部分或什么的