Skip to main content

Hello,

I'm having difficulty getting the String Formatter to work for me (I'm confident this is the right transformer I need to use.) I am trying to convert values stored as a number such as "23.012" to text in the following format: "000.0000". The destination output being "023.0120".

I'm sure it's incredibly easy, but I've had a play about with it and I'm getting nowhere.

Would be massively grateful for any help.

Thanks!

Hi @cjones28, you can use the StringFormatter with this format specification.

08.4f

Here, ".4f" specifies that the representation would be a decimal point number with 4 decimal places; "08" specifies that the entire resulting string would be at least eight characters and padded by leading zeros if the string length is less than 8 characters.


Hi @cjones28, you can use the StringFormatter with this format specification.

08.4f

Here, ".4f" specifies that the representation would be a decimal point number with 4 decimal places; "08" specifies that the entire resulting string would be at least eight characters and padded by leading zeros if the string length is less than 8 characters.

Excellent resolution with this transformer StringFormatter @takashi

 


Hi @cjones28

I created a Source file Excel format to simulta your case in 4 possible values.

The Workspace Template file that I created is split the attribute Values and count the elements.

Two Bookmars ( Format 1 and Format 2 ) was created to works prefix and sufix:

Result in FME Data Inspector:

Attached the Workspace Template - FMWT - workspace-format-string.fmwt

Thanks,

Danilo


@takashi I've tried the suggested method (it might be worth mentioning that the reader in this instance is a CSV file):

Unfortunately the excel output is still appearing in exactly the same format as in the originating CSV.

Thanks

Chris


@takashi I've tried the suggested method (it might be worth mentioning that the reader in this instance is a CSV file):

Unfortunately the excel output is still appearing in exactly the same format as in the originating CSV.

Thanks

Chris

You had to mention that the destination format was Excel.

 

Since Excel automatically removes leading and trailing zeros from numeric values by default, the StringFormatter would not be helpful. Instead, you will have to set a custom format in the Excel writer feature type. e.g.

 

 


You had to mention that the destination format was Excel.

 

Since Excel automatically removes leading and trailing zeros from numeric values by default, the StringFormatter would not be helpful. Instead, you will have to set a custom format in the Excel writer feature type. e.g.

 

 

Many thanks @takashi!

Reply