Skip to main content
Question

jsontemplater turns 2-decimal number 1.21 into 1.2100000381469727

  • April 16, 2026
  • 3 replies
  • 32 views

arnovananrooij
Contributor
Forum|alt.badge.img+5

Hi,

I use a JSONTemplater to make a geojson with nested attributes. It works fine. The only thing I notice is that I have a number in real32 (1.21) and when it comes out of the JSONTemplater it has the value 1.2100000381469727. The extra decimals apear out of nowhere. How can I change these back to the original? Or can I use some kind of casting? 

I use FME 2023.2.5.

Thank you

3 replies

david_r
Celebrity
  • April 16, 2026

You can use XQuery expressions inside the JSONTemplater. Example rounding the attribute "value" to two decimals:

{ "value":{fn:round(xs:double(fme:get-attribute("value")), 2)} }
Result:

{ "value" : 1.23 }

You can find a reference of all the XQuery and XPath functions here: https://www.w3.org/TR/xpath-functions-31/ 


s.jager
Influencer
Forum|alt.badge.img+23
  • Influencer
  • April 16, 2026

Hoi Arno,

Both the JSONTemplater and the XMLTemplater “suffer” from this problem. There is a good explanation for it though, which you can find in this thread: XMLtermplater vs. XSD-driven and a little problem | Community


david_r
Celebrity
  • April 16, 2026

Just to provide some background, this “problem” is not related to FME but to floating point precision in general, and how computers represent floating point numbers internally. Basically, floating point (real) numbers cannot, in general, be accurately represented in fixed space such as binary. This means that all floating point rounding errors cannot be eliminated, only managed.

Some systems go to great lengths to hide (manage) these imperfections from the users, including Python and FME, but we can sometimes, inadvertently, cause cracks in the façace and we end up with the real, internal value, and you get something like 1.2100000381469727 rather than the expected 1.21.

This is a fairly good introduction: