# How to convert from Java Math BigDecimal

**URL:** <https://forum.inductiveautomation.com/t/how-to-convert-from-java-math-bigdecimal/108980>\
**Category:** Ignition\
**Created:** [July 27, 2025, 1:04pm UTC](https://forum.inductiveautomation.com/t/how-to-convert-from-java-math-bigdecimal/108980 "2025-07-27T13:04:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [July 27, 2025, 1:04pm UTC](https://forum.inductiveautomation.com/t/how-to-convert-from-java-math-bigdecimal/108980/1 "2025-07-27T13:04:25Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [July 28, 2025, 9:50am UTC](https://forum.inductiveautomation.com/t/how-to-convert-from-java-math-bigdecimal/108980/2 "2025-07-28T09:50:51Z")

</div>

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

Any idea?

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [July 28, 2025, 12:31pm UTC](https://forum.inductiveautomation.com/t/how-to-convert-from-java-math-bigdecimal/108980/3 "2025-07-28T12:31:06Z")

</div>

have you tried to float both numbers?

```python
intVariable = 42

decVariable = 3.1415926

addedVars = float(intVariable) + float(decVariable)

```

---

<div class="post-metadata">

**Author:** ![clifford.ayer](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/clifford.ayer/32/78030_2.png) [@clifford.ayer](https://forum.inductiveautomation.com/u/clifford.ayer)\
**Post date:** [July 28, 2025, 1:35pm UTC](https://forum.inductiveautomation.com/t/how-to-convert-from-java-math-bigdecimal/108980/4 "2025-07-28T13:35:18Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [August 12, 2025, 10:46pm UTC](https://forum.inductiveautomation.com/t/how-to-convert-from-java-math-bigdecimal/108980/5 "2025-08-12T22:46:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [August 13, 2025, 2:03am UTC](https://forum.inductiveautomation.com/t/how-to-convert-from-java-math-bigdecimal/108980/6 "2025-08-13T02:03:10Z")

</div>

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

```python
	# 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

```
