Skip to main content
Question

Converting a String to a Number

  • November 15, 2012
  • 6 replies
  • 3159 views

How can I convert a string to a number so I can perform arithmetic calculations?

6 replies

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • November 15, 2012
HI,

 

 

If you have a digit, it should not be an issue, otherwise have a look at the StringFormatter.

 

 


davideagle
Contributor
Forum|alt.badge.img+21
  • Contributor
  • November 15, 2012
The StringFormatter is the way to go as Itay suggests...

 

 

You can also consider the @Evaluate function to allow string based transformers to consider the value as a number, like:

 

 

@Evaluate(<STRING>)

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • November 16, 2012
Yes, in general FME will just automatically convert any string to a number when it needs to. You can do this with the new String Editors that are part of any parameter (click on the down-arrow to the right, and you'll see the string/math editors there) -- there are always "math functions" there and you can just refer to attributes inside of the math functions -- for example @double(@Value(myAttr)) -- all possibly by drag and drop.

david_r
Evangelist
  • November 19, 2012
When handling floating point numbers with international source data, there can arise a situation where FME is unable to convert a string to a number if the decimal delimiter in your input data differs from the one defined on your system. Notably, the decimal delimiter is "," (comma) in some regions and "." (point) in others.

 

 

To resolve such problems, use a StringReplacer to set the correct decimal delimiter before doing arithmetic operations, that will usually take care of it.

 

 

David

robd
Contributor
Forum|alt.badge.img
  • Contributor
  • September 9, 2014
If StringFormatter doesnt work with integers an alternative is to use an AttributeRounder before ExpressionEvaluator round to 1 or 2 dp, then round back to 0 after the ExpressionEvaluator.

akunyer
Participant
Forum|alt.badge.img+1
  • Participant
  • January 8, 2019
fmelizard wrote:
Yes, in general FME will just automatically convert any string to a number when it needs to. You can do this with the new String Editors that are part of any parameter (click on the down-arrow to the right, and you'll see the string/math editors there) -- there are always "math functions" there and you can just refer to attributes inside of the math functions -- for example @double(@Value(myAttr)) -- all possibly by drag and drop.

it works !!! thanks


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