Skip to main content
Solved

How to use the ExpressionEvaluator?

  • December 16, 2014
  • 9 replies
  • 33 views

Forum|alt.badge.img
I wonder how to use the ExpressionEvaluator correctly:

 

 

If I do: 7/2 , the result is 3 in a string attribute not 3.5

 

 

If I do: @Value(Population2011)/@Value(PopulationTotal)

 

 

where Population2011 and PopulatonTotal are Real64 numbers, the result is 0 in a string attribute.

 

 

I realize the output of the ExpressionEvaluator is a string without decimal values. How can I keep the decimals?

Best answer by fmelizard

documentation:

 

5 / 4

 

 

returns 1, while

 

 

5 / 4.0

 

 

and

 

 

5 / (4 + 0.0)

 

 

both return 1.25.
View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, 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.

9 replies

Forum|alt.badge.img
  • Author
  • December 16, 2014
Even if I do @Value(Population2011)/@Value(PopulationTotal) * 100 the result is 0

 

 

why?

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • Best Answer
  • December 16, 2014
documentation:

 

5 / 4

 

 

returns 1, while

 

 

5 / 4.0

 

 

and

 

 

5 / (4 + 0.0)

 

 

both return 1.25.

Forum|alt.badge.img
  • Author
  • December 16, 2014
Ok so I have to do:

 

 

(@Value(Population2011)+ 0.0) / (@Value(PopulationTotal)+ 0.0) * 100.0

 

 

thats weird but I'll go with that...

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • December 17, 2014
Hi,

 

 

Itay is right. 5/4 returns 1, in FME 2014 and earlier.

 

But I heard that the behavior will be changed in FME 2015.

 

I discussed about this here just a few days ago.

 

3/2 returns 1 or 1.5? (http://fme-memorandum-takashi.blogspot.com/2014/12/32-returns-1-or-15.html)

 

 

It would be a significant change, I hope that Safe officially announces about this.

 

 

Takashi

Forum|alt.badge.img
  • Author
  • December 17, 2014
Very interesting blog Takashi. I wonder however why the type of attribute is not preserved in the ExpressionEvaluator. The output seems to always be a string, not a int or a float. That's what confuse me. If you do int(3/2) the resut is a string with value 1 not an integer with value 1. If you do 3.0/2 the output is a string with 1.5 value not a float.

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • December 17, 2014
It's one of frequently asked questions. The answer is here.

 

FME Workbench documentation > Attributes (http://docs.safe.com/fme/html/FME_Workbench/Default.htm#3D/Attributes.htm)

 

 

"FME stores all attributes as character strings and automatically converts between a string representation and a numeric representation as needed."

 

... basically.

Forum|alt.badge.img
  • December 17, 2014

Hi all,

 

Yes, in FME2014 or earlier we go with the computing standard that processing two integers gives an integer result (so 7/2=3). In FME2015 we're going with floating point values instead, so 7/2=3.5

 

 

Old workspaces will run as before, with exactly the same results as before, until you open the transformer dialog. Then a warning will pop up to tell you that it has been updated to floating point.

 

 

But we figure it would be a rare case where a user did want 7/2=3, and most would have used 7/2.0 (or similar) which will just operate as it did before. So all should be good.

 

 

As for attribute types, as Takashi says, we've not worried too much before. We just converted as necessary. However, we're again changing to improve this. For example, I  just tried 7/2 in FME2015 and got:

 

 

Attribute(64 bit real) : `_result' has value `3.5'

 

 

I don't think we'll get too strict though. Otherwise we'd end up having "cast" transformers to convert type, whereas we'd prefer the transformers to just work, whatever the type.

 

 

Hope this helps

 

 

Mark

 

 

Mark Ireland

 

Product Evangelist

 

Safe Software Inc.

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • December 17, 2014
Hi Mark, I've noticed the improvement concerning attribute types in FME 2015 beta.

 

I think that the description I quoted in my previous post should also be updated.

 

Takashi

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • December 18, 2014
A popular in your eyes "rare" case, wich i use often:

 

 

 

Slect every 2nd, 3d etc. ..

 

 

Tester: @Counter/2=@Counter/2.0

 

Tester: @Counter/3=@Counter/3.0

 

 

..and of course there are alternatives to do this..but this is by far the most elegant one.

 

 

There are more uses for the difference:

 

Like making a list where 
 somevalue/@Testvalue
 

 

drops to zero (of course be aware of zero devide..snore)

 

or other preset or even periodic value:

 

 

somevalue/@Testvalue = (counter/2)/(counter/2.0)

 

 

And more cases etc.

 

 

Not that rare of use.

 

Luckily, tcl still keeps it up. :)

 

 

 

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