Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

groovy decimal string to integer

Tags:

groovy

boomi

Hi All: I receive a decimal in string format and want to convert it to Integer in groovy. could not find any solution so far. For eg: I get the string value as "100.0" and I need the output as 100. Please help.

I plan to run this groovy script in boomi.

like image 930
NK7983 Avatar asked Sep 19 '26 05:09

NK7983


1 Answers

First convert to float, then to integer:

def s = "100.0"
def f = s.toFloat()
def i = f.toInteger() //or (int)f

or one line,

def i = "100.0".toFloat().toInteger()
like image 121
aldrin Avatar answered Sep 22 '26 08:09

aldrin