user10009190
user10009190

Reputation:

how to truncate decimal places in databricks without rounding off in databricks?

select truncate(12.455555,2)

I was trying to truncate the decimal value in the database from databricks but it was giving me the following error. it gave the same error when I tried executing a simple statement for trimming the decimal places given above.

Error-

Error in SQL statement: AnalysisException: Undefined function: 'truncate'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 7

Can anyone tell me how we can truncate the decimal places without rounding off the decimals?

Upvotes: 2

Views: 5960

Answers (1)

Mohana B C
Mohana B C

Reputation: 5487

You can use substring.

spark.sql("select substring(12.455555,0, instr(12.455555,'.')+2) as out").show()

+-----+
|  out|
+-----+
|12.45|
+-----+

Upvotes: 0

Related Questions