我希望将双精度字段连接到一个字符串字段中,从而降低精度(6个数字)。
例如:从lat=38.04900573076923长=-4.039010807692307
我想要location=38.049005,4.090108
奇怪的是,这并不像预期的那样工作:
df.withColumn("location", concat(col("lat").cast(DecimalType(6, 6)), lit(","), col("lon").cast(DecimalType(6, 6)))因此,location始终为空。
看看DoubleType,它不是从DecimalType继承的,所以这听起来很合乎逻辑。
做这件事的好方法是什么?
谢谢。
发布于 2019-10-18 22:57:21
取而代之的是取整取值如何?
df.withColumn("location", concat(round(col("lat"), 6), lit(","), round(col("lon"), 6)))您可能需要将round()转换为字符串,但这可能是固有的。
https://stackoverflow.com/questions/58453248
复制相似问题