skip to Main Content

I need to generate a large array of numbers ranging from 0.00 to say 10000000.00
i.e
0.01
0.02
0.03

1.51
1.52
1.583
… etc

After looking around, I tried this answer which works fine for integers but however not working for decimals

4

Answers


  1. You didn’t specify a language, so I will use Python.

    import numpy as np
    
    numbers = np.arange(0, 10000000.01, 0.01)
    
    # Print first 10 elements
    print(numbers[:10])
    
    # Print last 10 elements
    print(numbers[-10:])
    
    
    Login or Signup to reply.
  2. A simple way, try this:

    let array = [];
    for (let i = 0; i <= 1000000000; i++)
    {
       array.push(i * 0.01);
    }
    
    Login or Signup to reply.
  3. const arr = Array.from(new Array(10000000), (_, index) => (index / 100).toFixed(2));
    
    console.log(arr);
    

    With this code, you will get an array of the numbers described in the question, after the dot there will be 2 numbers: 0.00, 0.01 and so on.

    Login or Signup to reply.
  4. Try the following

    let array = [];
    let val = 0.00;
    do{
       val += 0.01;
       array.push(val);
    }while(val<1000000000.00);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search