Rahul
Rahul

Reputation: 78

Printing larger numbers with batch script

When I am printing these numbers in batch script they are displaying some values other than these numbers ,how to print these values in windows?

for /L %%n in (181729000010,1,181729000012) do echo %%n

Upvotes: 1

Views: 295

Answers (4)

lit
lit

Reputation: 16256

I know you already have a solution. Here is one that works with numbers.

FOR /F %%i IN (
    'powershell.exe -NoProfile -Command ^
        "for ($i=181729000010; $i -le 181729000012; $i++) { $i }"'
) DO (ECHO %%i)

Note that the PowerShell Range operator .. is limited to [int32] sized numbers.

Upvotes: 1

Magoo
Magoo

Reputation: 80113

for /L %%n in (9000010,1,9000012) do echo 18172%%n

should operate quite happily to do what you ask.

If you show us your actual problem, we may be able to suggest a solution. You appear to have asked us to fix a solution to an unknown problem.

Upvotes: 1

Compo
Compo

Reputation: 38654

For the purpose of your question example, just change the command to:

For /L %%A In (29000010,1,29000012) Do Echo 1817%%A

Upvotes: 1

MichaelS
MichaelS

Reputation: 6042

This is called an integer overflow. Batch can only handle numbers up to 2^31 -1 = 2147483647 as it only works with 32bit integers.

The answer to your question is: it's impossible.

However, if it is all just about printing, there is no problem:

ECHO 181729000010

works just fine. It's because in this case it is handled as a string and not as a number. But as soon as you try to do calculations with numbers bigger than 2147483647, you will fail.

Your code for /L %%n in (181729000010,1,181729000012) do echo %%n iterates over numbers from 181729000010 to 181729000012 which means, it adds 1 to the index in each iteration starting with 181729000010 + 1 which is a calculation.

Upvotes: 2

Related Questions