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:ย 

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_Fatma
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_Fatma
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! ๐Ÿš€

 

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