How to convert from Java Math BigDecimal

How do I deal with datatype changing to java math.decimal on the fly, this is because user input decimal point on the numeric input field.

I have a numeric field that represent percentage.
I divide numeric field value by 100 and writes to a document tag.
For some reason when I read the document tag, it will return number with Java Big Decimal.
I received the ff error:

TypeError: unsupported operand type(s) for +: 'int' and 'java.math.BigDecimal'

I am thinking of adding a try except clause.
But can't imagine how it would be.

Any idea?

have you tried to float both numbers?

intVariable = 42

decVariable = 3.1415926

addedVars = float(intVariable) + float(decVariable)

I have experienced a similar issue before: when using 'import ast' to export an XML file into a dictionary, many of the floats were being cast as BigDecimal. I wonder if this is a relic of the Java backend.... Anyways, you may want to "import java.math.BigDecimal" and use the built-in method "someBDNumber.floatValue()" to recast as a float after checking "type(someBDNumber)". Hopefully that may it least lead you to a solution!

This is weird.

I opened designer, clicked run button. - I got the BigDecimal error, numeric input field returns BigDecimal datatype.

So I changed numeric input field value to different value, and back to its previous value. - This time No error, and numeric input field returns Float Data Type.

When does value becomes BigDecimal Data Type?

– The numeric field is bidirectionally bound directly to Document Tag’s key.

– Whole document tag is read via custom property which the key’s value returns BigDecimal.

Update:

I think I found the point when it returns BigDecimal:
When tag does not exist, I create tag via system.tag.configure command. And set the initial numeric value, during this time it will return BigDecimal

I fixed it, on the binding to custom property reading a document tag:

	# convert big decimal to float
	if "PyDocumentObjectAdapter" in str(type(value)):
		d={}
		for k in value:
			try:
				d[k] = float(str(value[k]))
			except:
				d[k] = value[k]
		return d
	else:
		return value