Pipecraft
2023-06-05 13:25:09 +08:00
把开头连续的 0 去掉就可以。
```
function removeLeadingZero(num) {
const regex = /^([+-]?)0+(?=\d)/
return num.replace(regex, "$1")
}
console.log(removeLeadingZero("00"))
// 0
console.log(removeLeadingZero("000"))
// 0
console.log(removeLeadingZero("01"))
// 1
console.log(removeLeadingZero("001"))
// 1
console.log(removeLeadingZero("0.1"))
// 0.1
console.log(removeLeadingZero("+0.1"))
// +0.1
console.log(removeLeadingZero("-0.1"))
// -0.1
console.log(removeLeadingZero("00.1"))
// 0.1
console.log(removeLeadingZero("0012340012"))
// 12340012
console.log(removeLeadingZero("+0010086"))
// +10086
console.log(removeLeadingZero("-0010086"))
// -10086
console.log(removeLeadingZero("+000000"))
// +0
```