<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Issue with round off value while loading to delta table in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/issue-with-round-off-value-while-loading-to-delta-table/m-p/81159#M36243</link>
    <description>&lt;P&gt;I have a &lt;EM&gt;float&lt;/EM&gt; dataype column in delta table and data to be loaded should be &lt;EM&gt;rounded off to 2 decimal places&lt;/EM&gt;. I'm casting the column to &lt;EM&gt;&lt;STRONG&gt;DECIMAL(18,10)&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;type&amp;nbsp;and then using &lt;EM&gt;&lt;STRONG&gt;round&lt;/STRONG&gt;&lt;/EM&gt; function from &lt;EM&gt;&lt;STRONG&gt;pyspark.sql.function&lt;/STRONG&gt;&lt;/EM&gt; for rounding off values to 2 decimal places. When I display the dataframe before loading into delta table, I'm getting the desired 2 decimal place values, but after loading into the table, I'm getting values for that column upto 15 decimal places. Is this expected behavior in delta table or some cluster configurations needs to be changed for the same?&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jul 2024 14:39:39 GMT</pubDate>
    <dc:creator>DMehmuda</dc:creator>
    <dc:date>2024-07-30T14:39:39Z</dc:date>
    <item>
      <title>Issue with round off value while loading to delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-with-round-off-value-while-loading-to-delta-table/m-p/81159#M36243</link>
      <description>&lt;P&gt;I have a &lt;EM&gt;float&lt;/EM&gt; dataype column in delta table and data to be loaded should be &lt;EM&gt;rounded off to 2 decimal places&lt;/EM&gt;. I'm casting the column to &lt;EM&gt;&lt;STRONG&gt;DECIMAL(18,10)&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;type&amp;nbsp;and then using &lt;EM&gt;&lt;STRONG&gt;round&lt;/STRONG&gt;&lt;/EM&gt; function from &lt;EM&gt;&lt;STRONG&gt;pyspark.sql.function&lt;/STRONG&gt;&lt;/EM&gt; for rounding off values to 2 decimal places. When I display the dataframe before loading into delta table, I'm getting the desired 2 decimal place values, but after loading into the table, I'm getting values for that column upto 15 decimal places. Is this expected behavior in delta table or some cluster configurations needs to be changed for the same?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 14:39:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-with-round-off-value-while-loading-to-delta-table/m-p/81159#M36243</guid>
      <dc:creator>DMehmuda</dc:creator>
      <dc:date>2024-07-30T14:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with round off value while loading to delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-with-round-off-value-while-loading-to-delta-table/m-p/82239#M36573</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/114218"&gt;@DMehmuda&lt;/a&gt;,&amp;nbsp;The issue arises because floating-point numbers in Delta tables can retain more decimal places than expected. To ensure values are stored with the correct precision, explicitly cast the column to `DECIMAL(18,2)` before writing to the Delta table and define the Delta table schema with the desired precision. For example, use `df.withColumn("your_column", round(col("your_column").cast("decimal(18,2)"), 2))` before saving and specify the schema with `DecimalType(18, 2)` in your Delta table schema. This helps enforce precision during storage and writing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is there anything else you’d like to know or any other issues you’re facing with your setup?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 13:47:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-with-round-off-value-while-loading-to-delta-table/m-p/82239#M36573</guid>
      <dc:creator>Retired_mod</dc:creator>
      <dc:date>2024-08-07T13:47:35Z</dc:date>
    </item>
  </channel>
</rss>

