erdos / stencil

templating engine for DOCX and PPTX files
https://stencil.erdos.dev
Eclipse Public License 2.0
111 stars 12 forks source link

Dividing by dynamic value doesn't work #122

Closed bdobry closed 2 years ago

bdobry commented 2 years ago

Describe the bug

{%= one / two %}

raises an exception

Error rendering template!
java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
- java.lang.ArithmeticException Non-terminating decimal expansion; no exact representable decimal result.

for the payload

{
  "one": 4.3,
  "two": 3.0
}

It seems like like the partition part of division is causing the problem here. {%= one / 2 %} works fine but it breaks other way around.

Environment where template is rendered:

erdos commented 2 years ago

Thanks for reporting! The bug was that the custom JSON deserializer read BigDecimal values without precision and division would have resulted in a non-terminating decimal expansion. The solution is to limit the division precision to a finite number of digits. (8 in this case.)

Fixed in version 0.4.2 just released.

erdostw commented 2 years ago

(I forgot to also push tag, just did so build docker image should be available by now)