KNOWLEDGE BASE

How to output specific number of decimal places to CSV in Tableau Prep


Published: 02 Jun 2023
Last Modified Date: 06 Jun 2023

Question

How to output Number (decimal) with a decimal point and a specific number of decimal places.

When outputting Number (decimal) in CSV from Tableau Prep, the number of digits after the decimal point cannot be set arbitrarily.

If it's all 0's after the decimal point, a string of numbers without a decimal point is output, just as with integers.  This can be misleading for reading data in Tableau Desktop because Tableau Desktop determines the data type by the data type of the first 1,024 rows of the CSV.

Environment

  • Tableau Prep
  • Text Files

Answer

1. Calculate the integer part and decimal part separately.
  • Integer part
STR(FLOOR([sample_value]))
  • Decimal part.  This example rounds to four decimal places.  Please change the number of decimal places according to the number of significant digits in the actual data and the purpose of the data.
RIGHT("000"+STR(ROUND([sample_value]*10000)),4)
2. Combine the Integer part and the Decimal part with a decimal point.
[Integer part] + '.' + [Decimal part]
Please see the Attachments section of this article to find the example flow file for details.
Did this article resolve the issue?