Skip to main content
Solved

Output Josn attribute values showing more precision values ? even passed rounding of 2!

  • October 25, 2021
  • 5 replies
  • 91 views

I am converting ESRI gdb tables to Josn format(text_line), but unfortunately few of attribute values are given extra/unnecessary precision?

data from tables : "aos" : 105.20 ,"aos" : 293.22

output generated : "aos" : 105.20999999999999, "aos" : 293.22000000000003

To avoid this I have used attribute rounder , but no use, client required only 2 digits after (it should be float) . could some one help to resolve this issue on this.

I have used the below transformers

  1. gdb reader
  2. attribute manager and attribute rounder
  3. Josn templater
  4. Text file writer (text_line)

Thanks in advance

Chandra Sekhar Guda

 

 

Best answer by david_r

If you want to keep "aos" as a proper floating point value in the JSON, try using fn:round() in the expression of the JSONTemplater, e.g.

"aos": fn:round(fme:get-attribute("my_aos_attribute"), 2)

This will round "my_aos_attribute" to the nearest 2 decimal places and output it as "aos".

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.

5 replies

redgeographics
Celebrity
Forum|alt.badge.img+61

Since you're going to text, the StringFormatter is probably the best way to go, using .2f as the format string should do the trick.


david_r
Celebrity
  • Best Answer
  • October 25, 2021

If you want to keep "aos" as a proper floating point value in the JSON, try using fn:round() in the expression of the JSONTemplater, e.g.

"aos": fn:round(fme:get-attribute("my_aos_attribute"), 2)

This will round "my_aos_attribute" to the nearest 2 decimal places and output it as "aos".


  • Author
  • October 25, 2021

If you want to keep "aos" as a proper floating point value in the JSON, try using fn:round() in the expression of the JSONTemplater, e.g.

"aos": fn:round(fme:get-attribute("my_aos_attribute"), 2)

This will round "my_aos_attribute" to the nearest 2 decimal places and output it as "aos".

Thank you very much David_r, it worked, great


jelle
Contributor
Forum|alt.badge.img+21
  • Contributor
  • February 10, 2022

If you want to keep "aos" as a proper floating point value in the JSON, try using fn:round() in the expression of the JSONTemplater, e.g.

"aos": fn:round(fme:get-attribute("my_aos_attribute"), 2)

This will round "my_aos_attribute" to the nearest 2 decimal places and output it as "aos".

thanks, @david_r​ 

You saved my day!


chazbacca
Contributor
Forum|alt.badge.img+7
  • Contributor
  • November 30, 2023

gold! thank you for the question and answer!