I'm not sure this will work, since some of my values are whole integers and some legitimately have 4 or 5 decimal places.
This is a known issue - Tableau's built-in formatting does rounding however STR() conversions are using the underlying floating point numers without rounding. STR(ROUND([number], [decimal places])) and other methods will run into the same problem.
Here are my known workarounds:
1) If it's possible arrange a view to have multiple pills on Text or use a multiple axis crosstab http://public.tableau.com/views/conditionalformattingv4/Introduction with multiple pills on Label. Then you can use Tableau's built-in formatting for each pill with the " x " as part of the Text/Label Shelf configuration.
2) If you're using a live connection and your database has formatting function(s) can use RAWSQL or RAWSQLAGG to do the string formatting using SQL.
3) Do your own calculation. I got one from Tableau tech support a long time ago but it breaks under certain circumstances, I started working on my own but it's not done yet. I've attached the v2018.2 workbook I used for that plus the above screenshots.
Also there's problem with STR() conversion because while it will get the decimal place it won't put in any thousands separators either, so if your view needs that then there's a whole bunch of other math to use.
strings and rounding.twbx 230.6 KB
This data source is coming from Tableau Prep as a .hyper extract, so RAWSQL functions are a no-go. Too bad, too, since I've been looking for an excuse to use that RAWSQLAGG one! I think I'll probably just stick with using separate pills for now. Ultimately I think a more complicate worksheet structure is preferable to a super complicated calculation. Thanks for the clarification on this!
STR ( ROUND ( [Number_Decimal], n ) )
Dimension could be used on a view together with the
STR ( ROUND ( ATTR( [Number_Decimal] ), n ) )
Please find the attached.
STR_Test_v10.2_YF.twbx 2.3 MB