0

I want to remove the zeros,
I like to this model if i put in 1000 Then extra sheet shown all number from 1 to 1000 with every number check and remove the zeros.

Example :if I take in 10 then output like 1 2 3 .....8 9 1(the 10 remove the zero,and balance 1 is shown).

If I take in 500 then like 1 2 ......8 9 1 11 12 13.....19 2 21 22 23 .....29 3 31 32.. 98 99 1 11 12 13(101 102 103 remove the zeros) 488 499 5 (500 remove the zeros)

another example is if i take in 1000 then output like 1 2 ......8 9 1 11 12 13.....19 2 21 22 23 .....29 3 31 32.. 98 99 1 11 12 13(101 102 103 remove the zeros) 488 499 5 (500 remove the zeros) 51 52 53 54(501 502 503 remove zeros) ......at last 996 997 998 999 1 (1000 remove 3 zeros).

using java script and Html5...

Input number :

function printNoZeros() {

var numbers = document.getElementById("number").value;
var output = "";

for (var i = 1; i <= numbers; i++) {
    var noZero = i.toString().replace(/0/g, '');
    console.log(noZero);
}
document.getElementById("anumbers").innerHTML = output;

}

but don't get it...it's remove zero.but not shown in balance numbers

ex input is 20 output like 1 2 3 4 5 6 7 8 9 1 11 12 13 14 15 16 17 18 19 2

jerin
  • 45
  • 7
  • 1
    Kindly provide your input, current output(not working) and expected output.. – Rayon Feb 05 '16 at 05:51
  • OP wants an input of `10` to return `1 2 3 4 5 6 7 8 9 1` as in print all numbers with zeros stripped – Aziz Feb 05 '16 at 05:51
  • In a text box i like to put 10 or 100 or 500 or 1000 – jerin Feb 05 '16 at 05:52
  • output like mention the above text... – jerin Feb 05 '16 at 05:52
  • @Aziz, I could not see any efforts in posted question ;( – Rayon Feb 05 '16 at 05:53
  • ya same like 500 1000 but shown every numbers shown from 1 and remove all zeros.. – jerin Feb 05 '16 at 05:53
  • What's your question? What have you tried? – Chris Feb 05 '16 at 05:55
  • @Rfvgyhn all wants cooked food but no one wants to cook it. Its was simple solution and if you just google it there are hundred od answers to this question. But he did not tried it seems. – Rick Feb 05 '16 at 06:10
  • Possible duplicate of [Remove insignificant trailing zeros from a number?](http://stackoverflow.com/questions/3612744/remove-insignificant-trailing-zeros-from-a-number) – Rick Feb 05 '16 at 06:12

2 Answers2

5

Try this:

function printNoZeros(n) {
    for (var i = 1; i <= n; i++) {
        var noZero = i.toString().replace(/0/g, '');
        console.log(noZero);
  }
}

printNoZeros(110);

This uses a global find & replace on the number, and removes all zeroes. https://jsfiddle.net/19wLtwqh/1/

It currently prints them to the console, but it can be easily modified to print it somewhere else.

How does it work?

It uses a simple for loop, then it converts the variable i to a string, and replaces the zeroes using a global replace.

Hanlet Escaño
  • 17,114
  • 8
  • 52
  • 75
1

If you convert var to a string it will not display any trailing zeros, which aren't stored in the variable in the first place since it was created as a Number, not a String.

var a= 1.2000;

var b=a.toString()// 1.2

you can have a look at this Remove insignificant trailing zeros from a number?

Community
  • 1
  • 1
Rick
  • 373
  • 5
  • 19