How to convert a float to a string?

I thought this would be easy but I'm having trouble making this conversion.
Can you suggest where I went astray?

def testSyntax(){
  	def float OTf = 75.3
	def String OTs = toString(OTf)
	def int msgLen = OTs.length()
    log.info "string length$msgLen"
}

String OTs = OTf.toString()

2 Likes

Thanks.

I should have seen that as the next line is correct. I just have to get used to the different structure from C (not that I'm very good at C ) :slight_smile:

1 Like

Wait until you’re on your 8th or 9th language, all of the constructs start running together particularly when your bloodstream is low on caffeine. :sunglasses:

5 Likes

You dont need def in front of everything, that is typically only used if you dont specify a type at all. Some people write entire apps/drivers with no variable types at all and I hate it.

This should also work to make it a string, not sure which way is better or proper.

String OTs = "${OTf}"

1 Like

Not sure which is more efficient but both definitely work.