问题描述
大家好:我收到一个字符串格式的十进制数,并想在 groovy 中将其转换为整数。到目前为止找不到任何解决方案。例如:我得到的字符串值为“100.0”,我需要输出为 100。请帮忙。
我打算在 boomi 中运行这个 groovy 脚本。
解决方法
首先转换为浮点数,然后转换为整数:
def s = "100.0"
def f = s.toFloat()
def i = f.toInteger() //or (int)f
或一行,
def i = "100.0".toFloat().toInteger()