Converting String to Number


I am having trouble converting a string to a number. I am trying to get the height and width of an image and dividing it in half.

My snippet template looks like this:

	#set($alt = $sys.item.getProperty("img_alt").String)
	#set($height = $sys.item.getProperty("img1_height").String)
	#set($width = $sys.item.getProperty("img1_width").String)

	#set($mtop = $rx.string.extractNumber($height) / 2)
	#set($left = $rx.string.extractNumber($width) / 2)

	<a href="#displayfield('img_link')" rel="external"><img src="${src}" alt="${alt}" style="margin: -${mtop}px 0 0 -${mleft}px" width="${width}" /></a>

I’ve tried what seems like every possible variation of doing this. But nothing works. Using $rx.string.extractNumber() does return the proper value, but it fails when I try dividing the value.

Has anyone had any success with converting a string to a number?

Nick D

I’ve had success with $tools.math.* ie in your case

#set($mtop =  $tools.math.div($height, '2'))##

that did the trick! Thanks a lot!