记录一个小数转百分数

100 阅读1分钟
const toDecimal = (num) =>
num.toString()
.replace(/$/, '00%')
.replace(/(?<=\.\d{2})/, '.')
.replace(/\./, '')
.replace(/^0+/, '')
.replace(/^(?=\.)/, '0')
.replace(/(?<=\.\d{2,})0*(?=%)/, '')
.replace(/^(?=%)/, '0.00')
.replace(/(?<=\.)(\d)(?=%$)/, '$10')