Quantcast
Channel: How to convert column values from string to decimal? - Stack Overflow
Browsing latest articles
Browse All 6 View Live

Answer by Nav for How to convert column values from string to decimal?

In scala-spark you can use the DecimalType for conversion:import org.apache.spark.sql.types.DecimalTypeval convertedDf = dframe.withColumn("c_number",trim(col("c_a")).cast(DecimalType(20,0)))

View Article



Answer by Protyush Ghosh for How to convert column values from string to...

In scala :df=df.withColumn("col", $"col".cast(DecimalType(9,2)))

View Article

Answer by Sesha for How to convert column values from string to decimal?

This is after you have data in data frame with column that needs to be converted is readyTry:dframe.select($"column_name".cast("decimal(9,2)"))

View Article

Answer by Fabich for How to convert column values from string to decimal?

A Decimal has a precision and scale value, by default the precision is 10 and scale is 0.The precision is the maximum number of digit in your number. In your case you have more than 10 digits so the...

View Article

Answer by user6022341 for How to convert column values from string to decimal?

Try:dframe.withColumn("c_number", dframe.col("c_a").cast("decimal(38,0)"))

View Article


How to convert column values from string to decimal?

I'm having a dataframe which contains a really big integer value, example:42306810747081022358When I've tried to convert it to long it was working in the Java but not under the spark envrironment, I...

View Article
Browsing latest articles
Browse All 6 View Live


Latest Images