"double" population

  • Thread starter Thread starter vinnie
  • Start date Start date
V

vinnie

When i try to populate a dropdownlist menu, using a for cicle works
perfect: i get a list of int from ie 1 to 10. How an populate my
ddlist if working on the code i wish to get not longer a series of
integers, but a series of decimals?

Like this:
old fashion: (for i=1; i<=100; i++) i get 100 integers;

New fashion) i want to populate the same list, but using the decimals:
1; 1.01; 1.02; 1.03.... 99.99, 100.00

Is it possible?

Any suggestion?
 
vinnie said:
When i try to populate a dropdownlist menu, using a for cicle works
perfect: i get a list of int from ie 1 to 10. How an populate my
ddlist if working on the code i wish to get not longer a series of
integers, but a series of decimals?

Like this:
old fashion: (for i=1; i<=100; i++) i get 100 integers;

New fashion) i want to populate the same list, but using the decimals:
1; 1.01; 1.02; 1.03.... 99.99, 100.00

That's a lot of items. :)
Is it possible?

Anything is possible. :)

In your specific example, you appear to be incrementing your counter by
hundredths. So, you might use a loop like this:

for (decimal num = 1.0; num <= 100.0; num += 0.01)
{
// code to add to list here
}

You could also use floats, but I think the decimal type might work
better for your situation.

For that matter, you could use an integer, going from 100 to 10000,
where you divide by 100 when adding the value to the list.

Pete
 
vinnie,

You can always use the decimal type, like so:

for (decimal index = 1M; index <= 100M; ++index)
{
// Do something with the decimal here.
}

The for loop is not limited to numbers, it can be anything, the idea is
that it is in three parts. The first is the variable initializers, the
second is the check, and the third is the code that changes the state.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top