Skip to main content
Solved

JSONTemplater displaying floats values go long

  • March 20, 2019
  • 3 replies
  • 37 views

oliver.morris
Contributor
Forum|alt.badge.img+14

I am pushing data that I have cast as a double number to the JSONTemplater - it goes in as 0.09 once it comes out it gets longer becoming: "prod_index" : 0.09000000000000001

This seems like a floating point rounding number issue. Can anyone suggest a way around this.

Many Thanks,

Oliver

 

Best answer by david_r

Try something like:

{
    "prod_index": fn:round(fme:get-attribute("prod_index"), 2)
}

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

david_r
Celebrity
  • 8394 replies
  • Best Answer
  • March 20, 2019

Try something like:

{
    "prod_index": fn:round(fme:get-attribute("prod_index"), 2)
}

 


oliver.morris
Contributor
Forum|alt.badge.img+14
  • Author
  • Contributor
  • 176 replies
  • March 20, 2019

Try something like:

{
    "prod_index": fn:round(fme:get-attribute("prod_index"), 2)
}

 

did the trick thank you, it is a pity those functions arent listed in the text editor functions list on the left hand side.


david_r
Celebrity
  • 8394 replies
  • March 20, 2019

did the trick thank you, it is a pity those functions arent listed in the text editor functions list on the left hand side.

I agree. But you can find more information by googling for XQuery functions, e.g. "xquery round" etc.