cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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! 

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.