Solved

How can i fix the precision of 3 with StringFotmatter for all the values (.3f) ?


Badge +1

Hello,

 

 

In my workspace, I use LenghtCalculator to have the "Distance" from line.

 

I'd like to have three Numbers after .

 

I use Stringformatter on this attribute with Format String .3f but all value not have this setting.

 

 

Someone can help me to fix this?

 

 

I have also tried Attribute Manager with Math Opérator "ROund (Distance, 3). It's the same things.

 

 

Best Regards

 

 

icon

Best answer by mark2atsafe 8 May 2020, 23:12

View original

17 replies

Userlevel 1
Badge +10

What version of fme are you using? .3f works for me

Userlevel 2
Badge +12

The AttributeRounder is the easiest way to do this.

Hope this helps.

Userlevel 4

If I'm looking at the yellow highlight in the screenshot, it seems you want 0.11 formatted as 0.110?

If so, try this in a StringFormatter:

-0.3f
Badge +1

If I'm looking at the yellow highlight in the screenshot, it seems you want 0.11 formatted as 0.110?

If so, try this in a StringFormatter:

-0.3f

Thank you for your answer. I can have number like 1.110 , 2,130 etc..

 

 

Meanwhile I tested but It don't change anything. It's only data calculate with LengthCalculator

0684Q00000ArM4hQAF.png

 

 

 

Badge +1

The AttributeRounder is the easiest way to do this.

Hope this helps.

Hello,

 

 

Thank for your help.

 

 

The AttributeRounder give me the same result. The problem is only with data calculate with Length calculator.

 

 

 

Badge +1

What version of fme are you using? .3f works for me

Hello Thank for your answer.

 

I have try with FME 2020.0 Build 20200 and FME 2020.0.2 Build 20232.

 

If i make like you , it also works for me, but not with my attribute Lg2D (m)
Userlevel 4

Thank you for your answer. I can have number like 1.110 , 2,130 etc..

 

 

Meanwhile I tested but It don't change anything. It's only data calculate with LengthCalculator

 

 

 

Regardless, if you write "1.110" to Excel, it will still show up in Excel as 1.11, as this is a formatting issue, not a value issue.

Basically you should probably solve this issue in the Excel cell formatting settings.

Badge +1

Regardless, if you write "1.110" to Excel, it will still show up in Excel as 1.11, as this is a formatting issue, not a value issue.

Basically you should probably solve this issue in the Excel cell formatting settings.

Yes I can modify the parameters in Excel and It works but FME must handle it.

 

My purpose it's manage and configure data with FME and not Excel to simplify the work.

 

 

The other value like 335.670 are formatting when we want (Print Screen 1)

 

 

The print screen 2 show the act of formatting in excel and the result (ex 0.970 or 6.980).

 

 

Is it possible, it's a bug in FME?

 

 

Print Screen 1

Print Screen 2

 

 

 

 

Badge +2

You can use the rounder with 3 places and then a StringPadder with desired length as 3, right pad, and 0 as the padding value. That will append a 0. But, the -0.3f should work.

Userlevel 4

Yes I can modify the parameters in Excel and It works but FME must handle it.

 

My purpose it's manage and configure data with FME and not Excel to simplify the work.

 

 

The other value like 335.670 are formatting when we want (Print Screen 1)

 

 

The print screen 2 show the act of formatting in excel and the result (ex 0.970 or 6.980).

 

 

Is it possible, it's a bug in FME?

 

 

Print Screen 1

Print Screen 2

 

 

 

 

It's difficult to say if it's a bug, because it works for my tiny test case. Are you able to post a minimal workspace here that demonstrates the issue?

Badge +1

You can use the rounder with 3 places and then a StringPadder with desired length as 3, right pad, and 0 as the padding value. That will append a 0. But, the -0.3f should work.

 

Hello,

 

 

Sorry, your solution doesn't work with my Workspace and Data :(

 

 

 

Userlevel 4

I'm starting to suspect that FME is trying too hard to be intelligent and preserve the input float datatype, so that when it sees 1.110 cast as a float, it displays as 1.11, because realistically, that's what it is.

Try chaining two StringFormatters together, the first one with format string "s" to force the float to a string-like representation, then the next with "-0.3f" for padding.

Userlevel 1
Badge +10

I'm starting to suspect that FME is trying too hard to be intelligent and preserve the input float datatype, so that when it sees 1.110 cast as a float, it displays as 1.11, because realistically, that's what it is.

Try chaining two StringFormatters together, the first one with format string "s" to force the float to a string-like representation, then the next with "-0.3f" for padding.

Wonder if it could be related to the attribute type preservation in 2020?

https://knowledge.safe.com/questions/112114/attribute-data-type-preservation-in-fme-2020.html

Badge +1

I'm starting to suspect that FME is trying too hard to be intelligent and preserve the input float datatype, so that when it sees 1.110 cast as a float, it displays as 1.11, because realistically, that's what it is.

Try chaining two StringFormatters together, the first one with format string "s" to force the float to a string-like representation, then the next with "-0.3f" for padding.

Hello.

 

I try your solution, but it doesn't work :(

 

 

Badge +1

Wonder if it could be related to the attribute type preservation in 2020?

https://knowledge.safe.com/questions/112114/attribute-data-type-preservation-in-fme-2020.html

Perhaps, but i have another attribute that i calculate with Arithmetic Editor and it's works.

 

Userlevel 4
Badge +25

I covered the answer to this question (I hope) in the question-of-the-week post here:

https://knowledge.safe.com/questions/113630/question-of-the-week-writing-fixed-length-numbers.html

I think the problem is partly each of these:

  • The Table View window is not showing you the correct value. The StringFormatter really does return 0.110 and the Logger transformer proves this.
  • When you write to Excel, the column is a number, and a number column in Excel automatically trims trailing zeros. To fix this you must either:
    • Use a String column type in the FME schema definition
    • Set up an Excel file in which the number is defined as 3 decimal places, and use that as the template in FME. Then a number type shows the correct 3 places.

I hope this is helpful.

Badge +1

I covered the answer to this question (I hope) in the question-of-the-week post here:

https://knowledge.safe.com/questions/113630/question-of-the-week-writing-fixed-length-numbers.html

I think the problem is partly each of these:

  • The Table View window is not showing you the correct value. The StringFormatter really does return 0.110 and the Logger transformer proves this.
  • When you write to Excel, the column is a number, and a number column in Excel automatically trims trailing zeros. To fix this you must either:
    • Use a String column type in the FME schema definition
    • Set up an Excel file in which the number is defined as 3 decimal places, and use that as the template in FME. Then a number type shows the correct 3 places.

I hope this is helpful.

Hello Mark

 

 

Thank for your answer.

The value is Always viewed as 0.11 in FME but I set up a Template Excel File where the number is defined as 3 decimals places and it's good.

 

 

Best Regards

 

 

Reply