1

I'm doing a division between two fields, but scientific notation always appears at the end of the number: Example: 636.57 / 1031995.85 = 6.168338758338999E-4

my code is: df.withColumn("value",coalesce(col("value_1"),lit(0))/coalesce(col("value_2"),lit(0)))

when i convert using cast("decimal(18,14)"), the result is:

6.1683386E-4

can anyone help me?

I need the result : 6.168338758338999 I tried something similar but it didn't work either:

How to turn off scientific notation in pyspark?

  • Do you really want just the mantissa without the exponent? Or do you want it in proper decimal form such as "0.0006168338758338999"? – nigh_anxiety Jun 20 '22 at 20:33
  • @nigh_anxiety I just want it anyway : 6.168338758338999 – Carlos Eduardo Bilar Rodrigues Jun 20 '22 at 20:36
  • The answer to this question may help, https://stackoverflow.com/questions/40206592/how-to-turn-off-scientific-notation-in-pyspark – nigh_anxiety Jun 20 '22 at 23:58
  • @nigh_anxiety, The solution to this question is exactly what I sent in my code, and it doesn't work for me, because it changes the value, I just want to remove the scientific notation from the end and keep it in decimal – Carlos Eduardo Bilar Rodrigues Jun 21 '22 at 12:06
  • then what you probably want to so is something like `value = str(e_value).split("E")[0]`, where e_value is the number with scientific notation. That will give you a string. Convert to a float as needed. – nigh_anxiety Jun 21 '22 at 18:54

0 Answers0