cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Division Auto Truncates Decimal Even After Casting Inputs

alex_python
New Contributor II

Division of two numbers is auto truncating decimals and I can't get a more precise result.

Example of things I've tried:

10 / 60 => 0.17

cast(10 as float) / cast(60 as float) => 0.17

cast(cast(10 as float) / cast(60 as float) as float) => 0.17

round(10 / 60, 4) => 0.17

Expected result of all of these should be some form of

0.166666....7

Any help is appreciated

3 REPLIES 3

daniel_sahal
Esteemed Contributor

@Alex Pythonโ€‹ 

SELECT CAST(10/60 AS float)

This is working fine.

image 

This looks like it was in a notebook. Are you able to reproduce in Databricks SQL? That's where I'm seeing the truncation happen.

Anonymous
Not applicable

Hi @Alex Pythonโ€‹ 

Thank you for posting your question in our community! We are happy to assist you.

To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?

This will also help other community members who may have similar questions in the future.

Thank you for your participation and let us know if you need any further assistance! 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group