vue 金额保留两位小数,整数补0,不足两位补0
作者:
吃肉肉不吃肉肉 | 来源:发表于
2021-02-23 17:17 被阅读0次utils/index.js
export function toFixed(num) {
return (Math.round(num*100)/100).toFixed(2);
}
pages/index.vue
<template>
<div class="container">
{{num}}
</div>
</template>
<script type="text/ecmascript-6">
import { toFixed } from '@/utils'
export default {
data(){
return{
num:''
};
},
methods:{
let bar =1.1
this.num=toFixed(bar)
console.log(this.num)
//1.10
}
}
</script>
<style>
</style>
本文标题:vue 金额保留两位小数,整数补0,不足两位补0
本文链接:https://www.haomeiwen.com/subject/pkfdfltx.html
网友评论