What's the most elgant way in Groovy to specify a range of integers and the 0.5 steps between them? e.g.: 1, 1.5, 2, 2.5, 3, 3.5, 4
Edit: To clarify: As an end result I need a range object for use in a Grails constraint. Though I suppose a list would be OK too.
Best way I can see is using the step command.
i.e.
1.step(4, 0.5){ print "$it "}
would print out: "1 1.5 2.0 2.5 3.0 3.5"
A little late, but this works too
A one-liner for your above set:
(2..8)*.div(2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With