floating precision error in databricks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hey team,
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.
Our source system contains values like:
| 24.5638 | 24.560000 | 24.5600 | 24.5700 |
| 18.4421 | 18.440000 | 18.4400 | 18.4500 |
| 32.9187 | 32.910000 | 32.9100 | 32.9200 |
| 15.7749 | 15.770000 | 15.7700 | 15.7800 |
| 27.1365 | 27.130000 | 27.1300 | 27.1400 |
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.
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?
Would appreciate any suggestions from anyone who has dealt with this before.
Thanks
AB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hi @Aviral-Bhardwaj,
- In your first pair, 24.5638 became 24.560000 and 18.4421 became 18.440000. That's truncation (floor) to 2 decimal places.
- In your second pair, 24.5638 became 24.5700 and 18.4421 became 18.4500. That's a ceiling to 2 decimal places.
If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Aviral-Bhardwaj -
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.
Could you share:
- The target column’s data type (DESCRIBE TABLE your_table), e.g. is it DECIMAL(10,2), FLOAT, DOUBLE?
- How the data is loaded (JDBC read, Auto Loader, COPY INTO, or a file export) and whether a schema is inferred or explicitly defined?
- Whether any transformation in between uses CAST, ROUND, or format_number?
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.