Skip to main content
Solved

Rounding (floor) big numbers

  • July 15, 2020
  • 4 replies
  • 32 views

Forum|alt.badge.img

Hi,

I was formating big date numbers and I encountered a strange rounding effect when evaluating a big float number (see screenshot below). It can lead to issues when formating a datetime as FME needs seconds to be within 0 and 59 (60 not allowed).

As a workaround, I do the flooring using attributesplitter on strings (separator .).

However I wanted to ask whether this behavior is correct? I believe this is due to the size of the number.

Thanks for your answer

Best answer by ebygomm

It's not strictly speaking an fme issue, you would see the same output if you performed the same expression in python. It is related to the way the computers store numbers

https://floating-point-gui.de/

An alternative to the attribute splitter is to use an AttributeCreator/AttributeManager and a ReplaceRegEx statement to replace anything after the decimal and including the decimal point with nothing

e.g.

@ReplaceRegEx(@Value(number),\.[0-9]*,"")
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.

4 replies

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • Best Answer
  • July 15, 2020

It's not strictly speaking an fme issue, you would see the same output if you performed the same expression in python. It is related to the way the computers store numbers

https://floating-point-gui.de/

An alternative to the attribute splitter is to use an AttributeCreator/AttributeManager and a ReplaceRegEx statement to replace anything after the decimal and including the decimal point with nothing

e.g.

@ReplaceRegEx(@Value(number),\.[0-9]*,"")

Forum|alt.badge.img
  • Author
  • 6 replies
  • July 15, 2020

It's not strictly speaking an fme issue, you would see the same output if you performed the same expression in python. It is related to the way the computers store numbers

https://floating-point-gui.de/

An alternative to the attribute splitter is to use an AttributeCreator/AttributeManager and a ReplaceRegEx statement to replace anything after the decimal and including the decimal point with nothing

e.g.

@ReplaceRegEx(@Value(number),\.[0-9]*,"")

Thank you for the quick answer.


mark2atsafe
Safer
Forum|alt.badge.img+56
  • Safer
  • 2554 replies
  • July 17, 2020

Good question. Another thing you could do is run the features through a DateTimeConverter transformer with the option set to repair overflow. Then if you do get a "60" seconds, it will be changed to the properly time.

This article explains in a bit (well, lot) more depth: https://knowledge.safe.com/questions/108860/question-of-the-week-number-rounding-errors-in-dat.html


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • July 17, 2020

Good question. Another thing you could do is run the features through a DateTimeConverter transformer with the option set to repair overflow. Then if you do get a "60" seconds, it will be changed to the properly time.

This article explains in a bit (well, lot) more depth: https://knowledge.safe.com/questions/108860/question-of-the-week-number-rounding-errors-in-dat.html

Deja vu - I'm sure @david_r posted this same answer on this same question earlier in the week but i don't see it now