# IGN-11140 toDict() and java.math.BigDecimal

**URL:** <https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [October 12, 2023, 5:10pm UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400 "2023-10-12T17:10:29Z")\
**Posts on this page:** 12\
**Page:** 1

<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:** [October 12, 2023, 5:10pm UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/1 "2023-10-12T17:10:29Z")

</div>

So this just started happening.... When I call the .toDict() method on Memory Tag, of value type "document" all of the Integers and Floats are cast as \<type 'java.math.BigDecimal'\>.

```python
parsed = system.tag.readBlocking(["[default]SomeTag",])[0].value

parsed = parsed.toDict()

for key in parsed["chassis"]["abs"]["parameters"]:
	
	print parsed["chassis"]["abs"]["parameters"][key], type(parsed["chassis"]["abs"]["parameters"][key])

```

Resulting in

```python
>>> 
[1, 2] <type 'unicode'>
0 <type 'java.math.BigDecimal'>
[1, 2] <type 'unicode'>
34 <type 'unicode'>
4 <type 'java.math.BigDecimal'>
N <type 'unicode'>
[1, 2] <type 'unicode'>
0 <type 'java.math.BigDecimal'>
1 <type 'java.math.BigDecimal'>
R86 <type 'unicode'>
0 <type 'java.math.BigDecimal'>
0 <type 'java.math.BigDecimal'>
1 <type 'java.math.BigDecimal'>
1 <type 'java.math.BigDecimal'>

```

I pulled out what little hair I had left trying to figure out why my test scripts starting throwing KeyErrors when referencing dictionary keys...

Any ideas of why this is occurring? Note: the tag is written as a string and cast 'document' value type.

Thanks!

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [October 29, 2023, 5:27am UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/2 "2023-10-29T05:27:22Z")

</div>

Does the same problem occur if you write it `dict(parsed)` instead of `parsed.toDict()`?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 29, 2023, 9:05am UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/3 "2023-10-29T09:05:39Z")

</div>

> [@clifford.ayer](#):
>
> I pulled out what little hair I had left trying to figure out why my test scripts starting throwing KeyErrors when referencing dictionary keys...

I fail to see how converted **values** could make your script raise **`KeyErrors`**.  
What you're printing is the values and their types, not the keys.  
It could be written like this to make it clearer that you're not dealing with the keys:

```python
for key, value in parsed["chassis"]["abs"]["parameters"].iteritems():
	print value, type(value)

```

Can we see the script that raises the `keyError` ?

---

<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:** [October 31, 2023, 12:47am UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/4 "2023-10-31T00:47:24Z")

</div>

We were using the 'ast' library... once I pulled the ast implementation, everything returned to normal-- no casting of java.math.BD

---

<div class="post-metadata">

**Author:** ![jesusaltamirano600](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@jesusaltamirano600](https://forum.inductiveautomation.com/u/jesusaltamirano600)\
**Post date:** [March 25, 2024, 9:03pm UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/5 "2024-03-25T21:03:19Z")

</div>

Hello guys, can you share how did you remove the "ast implementation" you are talking about? I am having exactly the same issue.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 26, 2024, 8:10am UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/6 "2024-03-26T08:10:46Z")

</div>

We need to see the code to help you modify it. We can't just guess what you're dealing with.

---

<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:** [April 1, 2024, 5:02pm UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/7 "2024-04-01T17:02:43Z")

</div>

In my particular case, my team had imported the "ast" (abstract syntax tree) library for some of the scripting. The library had been purposely added thus removing the library import call stopped my INTs, FLOATs, ect. from being parsed incorrectly, or more precisely- stopped them from being parsed into unexpected python 'privatives'.

---

<div class="post-metadata">

**Author:** ![dgillbee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dgillbee/32/73838_2.png) [@dgillbee](https://forum.inductiveautomation.com/u/dgillbee)\
**Post date:** [April 4, 2025, 1:41pm UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/8 "2025-04-04T13:41:44Z")

</div>

I've stumbled across this same error.

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

```

I'm trying to perform a math function on a number that is store inside a document tag.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/e/2ec241b8c09031cb6524d838e642895291baf264.png)

Using the python cast raises another error.

```python
TypeError: float() argument must be a string or a number

```

The easiest way to resolve this is to use the java method to cast it the correct data type, in my case float.

```python
sourceVolume -= flowIn[flowSource] #This raises the TypeError
sourceVolume -= float(flowIn[flowSource]) #This raises another TypeError
sourceVolume -= flowIn[flowSource].floatValue() #This fixes the TypeError

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 4, 2025, 1:48pm UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/9 "2025-04-04T13:48:07Z")

</div>

Did you populate the value of this memory tag via e.g. system.tag.writeBlocking with a dictionary, or did you build it in the tag editor?

There's an existing ticket that is probably related if you set the value via scripted write.

---

<div class="post-metadata">

**Author:** ![dgillbee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dgillbee/32/73838_2.png) [@dgillbee](https://forum.inductiveautomation.com/u/dgillbee)\
**Post date:** [April 4, 2025, 1:56pm UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/10 "2025-04-04T13:56:43Z")

</div>

> [@Kevin.Herron](#):
>
> an existing ticket that is probably related if you set the value via scripted

It's a bit of a convoluted work flow. I am making a process simulation system so there is a lot of data being passed from one tag to another.

> UDT 1  
> Tag1 - Manual write in Tag Browser  
> Tag 2 - Expression tag reading UDT1/Tag1

> UDT2  
> Tag1 - Written by script from UDT1/Tag2  
> Tag3 - Script adds Tag1 to Tag3

Not sure if this helps at all.

---

<div class="post-metadata">

**Author:** ![atay](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/atay/32/6232_2.png) [@atay](https://forum.inductiveautomation.com/u/atay)\
**Post date:** [October 1, 2025, 8:20pm UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/11 "2025-10-01T20:20:06Z")

</div>

Hi Kevin, is there any updates on this ticket. Just came across the same error for a single value out of many to be cast to `java.math.BigDecimal`. The value was script written to a document memory tag, and the error occurred on an instance where I duplicated the tag to another folder. The value is 15.

Document tag - script written values, no errors.

Duplicate document tag - copy and paste of the above document tag, one of the values, 15, that were carried over is causing the type error.

Ignition version is **8.1.48 (b2025042910)**

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 1, 2025, 8:28pm UTC](https://forum.inductiveautomation.com/t/ign-11140-todict-and-java-math-bigdecimal/80400/12 "2025-10-01T20:28:40Z")

</div>

No, looks like it's pretty low priority. I'll poke the PM. If you contact support to create a ticket that will help visibility and priority.
