Quantcast
Channel: How to convert column values from string to decimal? - Stack Overflow
Viewing all articles
Browse latest Browse all 6

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

$
0
0

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 number can't be cast to a 10 digits Decimal and you have null values.

To avoid that you need to specify a precision large enough to represent your numbers :

dframe.withColumn("c_number", dframe.col("c_a").cast(new DecimalType(38,0)))

Note that the precision can be up to 38


Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>