How to do this in Groovy Range Object?
I want numbers from 0.1 to 2(such as 0.1,0.2,0.3,0.4 so on to 2.0), as I'm a groovy guy i decided Range
will do the job, and came with code like this:
def a = 0.1..2
println a
But its printing only 开发者_高级运维[0.1, 1.1]
as its output! So i can't do this in Range
? or by syntax is wrong?
Thanks in advance.
that's not trivial. The range object has a step method, but this allows only for integer steps. Another solution could be to define your own range object.
If a list is also ok, you can use the step method on a number:
0.1.step(2, 0.1){ print "$it "}
another solution:
(1 .. 20).collect{it/10}
精彩评论