Skip to main content
Solved

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


bernarddinon
Forum|alt.badge.img+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

 

 

Best answer by mark2atsafe

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.

View original
Did this help you find an answer to your question?

17 replies

ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • May 4, 2020

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


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • May 4, 2020

The AttributeRounder is the easiest way to do this.

Hope this helps.


david_r
Celebrity
  • May 5, 2020

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

bernarddinon
Forum|alt.badge.img+1
david_r wrote:

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

 

 

 


bernarddinon
Forum|alt.badge.img+1
erik_jan wrote:

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.

 

 

 


bernarddinon
Forum|alt.badge.img+1
ebygomm wrote:

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)

david_r
Celebrity
  • May 6, 2020
bernarddinon wrote:

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.


bernarddinon
Forum|alt.badge.img+1
david_r wrote:

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

 

 

 

 


Forum|alt.badge.img+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.


david_r
Celebrity
  • May 7, 2020
bernarddinon wrote:

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?


bernarddinon
Forum|alt.badge.img+1
jlbaker2779 wrote:

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 :(

 

 

 


david_r
Celebrity
  • May 8, 2020

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.


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • May 8, 2020
david_r wrote:

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


bernarddinon
Forum|alt.badge.img+1
david_r wrote:

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 :(

 

 


bernarddinon
Forum|alt.badge.img+1
ebygomm wrote:

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.

 


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • Best Answer
  • May 8, 2020

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.


bernarddinon
Forum|alt.badge.img+1
mark2atsafe wrote:

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

 

 


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