Reputation: 45
I'm new in spark Java API. I want to transform double with scientific format example: 1.7E7---->17000000,00.
MyDataSet is:
+---------+------------+
| account| amount |
+---------+------------+
| c1 | 1.7E7 |
| c2 | 1.5E8 |
| c3 | 142.0 |
I want to transform my dataset to something like this.
+---------+----------------------+
| account| amount |
+---------+----------------------+
| c1 | 17000000,00 |
| c2 | 1500000000,00 |
| c3 | 142,00 |
Can someOne guide me with an expression in spark Java to resolve this. Thanks in advance.
Upvotes: 0
Views: 3608
Reputation: 1863
I think you can do it like this. Don't forget import spark.sql.functions
Dataset<Row> myDataset = ....
myDataset = myDataset.withColumn("newAmount", col("amount").cast(DataTypes.DoubleType))
.drop(col("amount"))
.withColumnRenamed("newAmount","amount")
.toDF();
Upvotes: 3