cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

How to no round formating

William_Scardua
Valued Contributor

Hy guys,

I need to format the decimal values but I can`t round then

Screenshot 2024-03-20 at 10.01.52.png

have any idea ?

thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions

Kaniz
Community Manager
Community Manager

Hi @William_ScarduaIn Databricks, you can format decimal values without rounding them using a couple of approaches. Let’s explore some options:

  1. Using substring: You can use the substring function to extract a specific number of decimal places from your decimal value. For example:

    spark.sql("SELECT SUBSTRING(12.455555, 0, INSTR(12.455555, '.') + 2) AS truncated_value").show()
    

    This will give you the result: 12.451.

  2. Custom Formatting with format_number: The format_number function allows you to override the default rounding format. You can specify the desired number of decimal places. For instance:

    spark.sql("SELECT FORMAT_NUMBER(12.455555, 2) AS formatted_value").show()
    

    This will display: 12.462.

Remember that these solutions will trim the decimal places without rounding off the values. Choose the one that best fits your requirements! 🚀

 

View solution in original post

1 REPLY 1

Kaniz
Community Manager
Community Manager

Hi @William_ScarduaIn Databricks, you can format decimal values without rounding them using a couple of approaches. Let’s explore some options:

  1. Using substring: You can use the substring function to extract a specific number of decimal places from your decimal value. For example:

    spark.sql("SELECT SUBSTRING(12.455555, 0, INSTR(12.455555, '.') + 2) AS truncated_value").show()
    

    This will give you the result: 12.451.

  2. Custom Formatting with format_number: The format_number function allows you to override the default rounding format. You can specify the desired number of decimal places. For instance:

    spark.sql("SELECT FORMAT_NUMBER(12.455555, 2) AS formatted_value").show()
    

    This will display: 12.462.

Remember that these solutions will trim the decimal places without rounding off the values. Choose the one that best fits your requirements! 🚀

 
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.