Int to Float in Groovy

Find this useful? Support us: Star on GitHub 6
Category: Number | Language: Groovy

In Groovy, the tofloat() method can be used to convert an integer to a float. Here's an example:

def intNum = 10
def floatNum = intNum.tofloat()
println(floatNum) // Output: 10.0

In this example, the integer value 10 is assigned to the variable intNum. The tofloat() method is then called on intNum to convert it to a float value, which is assigned to the variable floatNum. The println() statement outputs the value of floatNum, which is 10.0.