I'm trying to multiply two columns in Spark. Both the columns are of type Double. The result of the multiplication between 26.0 and 0.001 is 0.026000000000000002 and not 0.0026. How do I resolve this?
>>> df.printSchema()
root
|-- age: double (nullable = true)
|-- name: string (nullable = true)
|-- mul: double (nullable = false)
>>> df.withColumn('res', df['age']*df['mul']).show()
+----+--------+-----+--------------------+
| age| name| mul| res|
+----+--------+-----+--------------------+
|25.0| Ankit|0.001| 0.025|
|22.0|Jalfaizy|0.001| 0.022|
|20.0| saurabh|0.001| 0.02|
|26.0| Bala|0.001|0.026000000000000002|
+----+--------+-----+--------------------+
Thanks