JS remove leading zeros

后端 未结 2 573
南旧
南旧 2021-01-23 10:52

In JavaScript, I want to remove the decimal place & the following zeros.

For example, my original number: \"0.00558\", I want to be left with \"558\".

Is thi

2条回答
  •  旧时难觅i
    2021-01-23 11:40

    you can do that by a simple regex replace.

    var number = "0.00558";
    number = number.replace(/^[0\.]+/, "");
    console.log(number);//number is now "558"
    

提交回复
热议问题