Groovy similar to Ruby fairly,in groovy language all of thing is object,that means you have to operate an object by invocation its method.For example 123.abs() will return the absolute value of this integer.Groovy support Integer and Floating point numeric.Indeed,Groovy implement every operator as a method,for example "+" implement as plus:123.plus(456) means 123+456the return value is 578,it's a integer,then on the other hand,for division operator,when you type and run 5/2 the result is 2.5,it's floating point numeric;now how about 6/2,what the result,I think the result is 3,an integer numeric,but I'm wrong,indeed all of the result of division operator is a floating point,even if the result look like an integer.so the result of 6/2 is 3.0,it's a floating point numeric.
And if you want to obtain an integer you should invoke the method intdiv:6.intdiv(2) then the result is an integer:3
Thursday, October 30, 2008
Subscribe to:
Post Comments (Atom)
1 comment:
At first time I though that it's weird to have everything as an object because it's simpler to write 2+3 than 2.plus(3). But when i need to convert some numbers or work with strings then i see that It's handy.
Second thing, maybe I'm wrong, but in my country 123+456=579 not 578 :P
Post a Comment