<?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 Re: floating precision error in databricks in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/floating-precision-error-in-databricks/m-p/175215#M56972</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/53460"&gt;@Aviral-Bhardwaj&lt;/a&gt;&amp;nbsp; -&amp;nbsp;&lt;/P&gt;&lt;P&gt;From your sample it looks like the values are losing everything past the 2nd decimal place (e.g. 24.5638 → 24.56 / 24.57), which usually points to the scale of the target column or a cast in the pipeline, not a Databricks display setting.&lt;/P&gt;&lt;P&gt;Could you share:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The target column’s data type (DESCRIBE TABLE your_table), e.g. is it DECIMAL(10,2), FLOAT, DOUBLE?&lt;/LI&gt;&lt;LI&gt;How the data is loaded (JDBC read, Auto Loader, COPY INTO, or a file export) and whether a schema is inferred or explicitly defined?&lt;/LI&gt;&lt;LI&gt;Whether any transformation in between uses CAST, ROUND, or format_number?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;If it’s a DECIMAL scale issue, the fix is to define the column with enough scale (e.g. DECIMAL(18,6)) and re-load. If you’re reading via JDBC, also check the source column’s precision/scale, since Spark maps it from the source metadata.&lt;/P&gt;</description>
    <pubDate>Sat, 31 Oct 2026 18:18:35 GMT</pubDate>
    <dc:creator>indradbxlearn</dc:creator>
    <dc:date>2026-10-31T18:18:35Z</dc:date>
    <item>
      <title>floating precision error in databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/floating-precision-error-in-databricks/m-p/175034#M56963</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;Hey team,&lt;/P&gt;&lt;P&gt;I ran into this issue back in 2019, but I don't recall how we resolved it. I'm looking for guidance from experienced Spark/Databricks engineers.&lt;/P&gt;&lt;P&gt;Our source system contains values like:&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;source in-databricks source in-databricks &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;24.5638&lt;/TD&gt;&lt;TD&gt;24.560000&lt;/TD&gt;&lt;TD&gt;24.5600&lt;/TD&gt;&lt;TD&gt;24.5700&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;18.4421&lt;/TD&gt;&lt;TD&gt;18.440000&lt;/TD&gt;&lt;TD&gt;18.4400&lt;/TD&gt;&lt;TD&gt;18.4500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;32.9187&lt;/TD&gt;&lt;TD&gt;32.910000&lt;/TD&gt;&lt;TD&gt;32.9100&lt;/TD&gt;&lt;TD&gt;32.9200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;15.7749&lt;/TD&gt;&lt;TD&gt;15.770000&lt;/TD&gt;&lt;TD&gt;15.7700&lt;/TD&gt;&lt;TD&gt;15.7800&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;27.1365&lt;/TD&gt;&lt;TD&gt;27.130000&lt;/TD&gt;&lt;TD&gt;27.1300&lt;/TD&gt;&lt;TD&gt;27.1400&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;My requirement is simple: perform a SELECT and see the exact values stored in the source. I don't want any rounding, truncation, casting, or formatting changes.&lt;/P&gt;&lt;P&gt;This is critical financial data where every decimal place matters. Is there a Spark/Databricks setting, data type handling issue, or display behavior that could cause precision differences between the source and Databricks?&lt;/P&gt;&lt;P&gt;Would appreciate any suggestions from anyone who has dealt with this before.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;AB&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 30 Oct 2026 16:12:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/floating-precision-error-in-databricks/m-p/175034#M56963</guid>
      <dc:creator>Aviral-Bhardwaj</dc:creator>
      <dc:date>2026-10-30T16:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: floating precision error in databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/floating-precision-error-in-databricks/m-p/175058#M56967</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/53460"&gt;@Aviral-Bhardwaj&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;DIV class="du-bois-light-typography css-mdu5st" data-genai-markdown-block="true"&gt;I don't think this is a display issue, and it isn't normal rounding either.&lt;/DIV&gt;
&lt;UL&gt;
&lt;LI data-genai-markdown-block="true"&gt;In your first pair, 24.5638 became 24.560000 and 18.4421 became 18.440000. That's truncation (floor) to 2 decimal places.&lt;/LI&gt;
&lt;LI data-genai-markdown-block="true"&gt;In your second pair, 24.5638 became 24.5700 and 18.4421 became 18.4500. That's a ceiling to 2 decimal places.&lt;/LI&gt;
&lt;/UL&gt;
&lt;DIV data-genai-markdown-block="true"&gt;In both cases, the trailing zeros indicate that the extra digits had already been removed before the data reached the table. They were later padded back out to a wider scale.&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;Databricks doesn't silently floor or ceil DECIMAL values. A&amp;nbsp;CAST&amp;nbsp;to a smaller scale rounds half up, so 24.5638 cast to&amp;nbsp;DECIMAL(10,2)&amp;nbsp;gives 24.56, not 24.57. The&amp;nbsp;&lt;A role="link" href="https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/data-types/decimal-type/" rel="noopener noreferrer" data-component-type="typography_link" data-component-id="codegen_webapp_js_genai_util_markdown.tsx_71" aria-disabled="false" target="_blank"&gt;DECIMAL type&lt;/A&gt;&amp;nbsp;docs have examples. DECIMAL columns are also displayed at their full declared scale. So something in your ingestion path is probably converting to 2 decimals on purpose, most likely an explicit&amp;nbsp;FLOOR,&amp;nbsp;CEIL&amp;nbsp;or&amp;nbsp;TRUNC, a target schema with scale 2, or a step in the extract tool.&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;CAn you run&amp;nbsp;DESCRIBE TABLE&amp;nbsp;on the Databricks table and on any staging or intermediate tables to check each column's precision and scale? You can also go through the pipeline code and any ETL or extract tool settings for rounding functions or a&amp;nbsp;DECIMAL(p,2)&amp;nbsp;cast. If you land files first, check what the CSV or Parquet files actually contain, and make sure you read them with an explicit DECIMAL schema rather than&amp;nbsp;inferSchema.&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;
&lt;DIV data-genai-markdown-block="true"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;If you read over JDBC, check the type mapping. For Oracle, for example,&amp;nbsp;NUMBER&amp;nbsp;without a declared precision maps to&amp;nbsp;DECIMAL(38,10)&amp;nbsp;(&lt;A role="link" href="https://learn.microsoft.com/en-us/azure/databricks/query-federation/oracle/" rel="noopener noreferrer" data-component-type="typography_link" data-component-id="codegen_webapp_js_genai_util_markdown.tsx_71" aria-disabled="false" target="_blank"&gt;Oracle type mappings&lt;/A&gt;). That keeps your 4 decimals, but a custom schema or a downstream cast can still cut them. You can set the exact type yourself with the JDBC&amp;nbsp;customSchema&amp;nbsp;option, for example&amp;nbsp;customSchema "amount DECIMAL(18,4)".&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;Avoid&amp;nbsp;DOUBLE&amp;nbsp;and&amp;nbsp;FLOAT&amp;nbsp;for financial data. They are base-2 types and can't represent many base-10 decimals exactly (&lt;A role="link" href="https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/data-types/double-type/" rel="noopener noreferrer" data-component-type="typography_link" data-component-id="codegen_webapp_js_genai_util_markdown.tsx_71" aria-disabled="false" target="_blank"&gt;DOUBLE type&lt;/A&gt;).&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;
&lt;DIV data-genai-markdown-block="true"&gt;Pick one record, such as the 24.5638 row, and trace it through each stage: source query result, landed file, bronze table, then final table. Run&amp;nbsp;typeof(col)&amp;nbsp;on the value at every stage. The stage where it first shows up as 24.56 or 24.57 is where the conversion happens. Define the column as&amp;nbsp;DECIMAL&amp;nbsp;with the same precision and scale as the source from that stage onward, and the values should match exactly.&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;If you share how you ingest the data (JDBC, Auto Loader, Lakeflow Connect or a third-party tool) and the column definition in the source, the community can help narrow it down.&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV data-genai-markdown-block="true"&gt;
&lt;P class="p1"&gt;&lt;FONT size="2" color="#FF6600"&gt;&lt;STRONG&gt;&lt;I&gt;If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;I&gt;&lt;/I&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 30 Oct 2026 19:56:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/floating-precision-error-in-databricks/m-p/175058#M56967</guid>
      <dc:creator>Ashwin_DSA</dc:creator>
      <dc:date>2026-10-30T19:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: floating precision error in databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/floating-precision-error-in-databricks/m-p/175215#M56972</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/53460"&gt;@Aviral-Bhardwaj&lt;/a&gt;&amp;nbsp; -&amp;nbsp;&lt;/P&gt;&lt;P&gt;From your sample it looks like the values are losing everything past the 2nd decimal place (e.g. 24.5638 → 24.56 / 24.57), which usually points to the scale of the target column or a cast in the pipeline, not a Databricks display setting.&lt;/P&gt;&lt;P&gt;Could you share:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The target column’s data type (DESCRIBE TABLE your_table), e.g. is it DECIMAL(10,2), FLOAT, DOUBLE?&lt;/LI&gt;&lt;LI&gt;How the data is loaded (JDBC read, Auto Loader, COPY INTO, or a file export) and whether a schema is inferred or explicitly defined?&lt;/LI&gt;&lt;LI&gt;Whether any transformation in between uses CAST, ROUND, or format_number?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;If it’s a DECIMAL scale issue, the fix is to define the column with enough scale (e.g. DECIMAL(18,6)) and re-load. If you’re reading via JDBC, also check the source column’s precision/scale, since Spark maps it from the source metadata.&lt;/P&gt;</description>
      <pubDate>Sat, 31 Oct 2026 18:18:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/floating-precision-error-in-databricks/m-p/175215#M56972</guid>
      <dc:creator>indradbxlearn</dc:creator>
      <dc:date>2026-10-31T18:18:35Z</dc:date>
    </item>
  </channel>
</rss>

