We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Learn more about funding links in repositories.
Report abuse
There was an error while loading. Please reload this page.
第417天 写一个方法把科学计数法转换成数字或者字符串
3+1官网
我也要出题
function c(a) { return a.replace(/^(\d+)(?:.(\d+))*eE(\d+)/,(_,a,a1,p,n)=>{ a1=a1||'' if(p==='-'&&n>0) { return '0.'+'0'.repeat(n-1)+a+a1 }else{ return a+(a1.length>n? a1.substr(0, n)+'.'+a1.substr(n): a1+'0'.repeat(n-a1.length)) } }) }
打破零回复
var a = -2243433.2242 var b = 1000000000000000000000 const numString = (str) => { return parseFloat(str).toLocaleString().replaceAll(',', '') } numString(a)// '-2243433.224' numString(b)// '1000000000000000000000' numString('1e+23')// '100000000000000000000000'
实际操作会有精度问题
Activity
treemonster commentedon Jun 10, 2020
function c(a) {
return a.replace(/^(\d+)(?:.(\d+))*eE(\d+)/,(_,a,a1,p,n)=>{
a1=a1||''
if(p==='-'&&n>0) {
return '0.'+'0'.repeat(n-1)+a+a1
}else{
return a+(a1.length>n? a1.substr(0, n)+'.'+a1.substr(n): a1+'0'.repeat(n-a1.length))
}
})
}
打破零回复
wind8866 commentedon Mar 3, 2022
实际操作会有精度问题