Handling decimal values in spark scala
I have data in a file as shown below: 7373743343333444. 7373743343333432. This data should be converted to decimal values and should be in a position of 8.7 where 8 are the digits before decimal and 7 are the digits after decimal. I am trying to read the data file as below: val readDataFile = Initialize.spark.read.format("com.databricks.spark.csv").option("header", "true").option("delimiter", "|").schema(***SCHEMA*****).load(****DATA FILE PATH******) I have tried this: val changed = dataFileWithSchema.withColumn("COLUMN NAME", dataFileWithSchema.col("COLUMN NAME").cast(new DecimalType(38,3)))
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.