Input field value - remove leading zeros

前端 未结 8 1915
南笙
南笙 2020-11-27 06:34

I have a textbox in Javascript. When I enter \'0000.00\' in the textbox, I want to know how to convert that to only having one leading zero, such as \'0.0

8条回答
  •  心在旅途
    2020-11-27 06:59

    Ok a simple solution. The only problem is when the string is "0000.00" result in plain 0. But beside that I think is a cool solution.

    var i = "0000.12";
    var integer = i*1; //here's is the trick...
    console.log(i); //0000.12
    console.log(integer);//0.12
    

    For some cases I think this can work...

提交回复
热议问题