Skip to main content
Solved

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


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".

View original
Did this help you find an answer to your question?

5 replies

redgeographics
Celebrity
Forum|alt.badge.img+50

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
david_r wrote:

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+16
  • Contributor
  • February 10, 2022
david_r wrote:

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+1
  • Contributor
  • November 30, 2023

gold! thank you for the question and answer!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings