Manish
Manish

Reputation: 117

divide two DF count but getting 0 in spark

I am trying to divide two DF count but getting 0 I think I need to do typecasting. Can you help me.

val subscribed = dataDF.where("Y='yes'").count
subscribed: Long = 5289
val Total = dataDF.count
Total: Long = 45211
val success = subscribed / Total
success: Long = 0 

Upvotes: 0

Views: 114

Answers (1)

mtoto
mtoto

Reputation: 24178

You have to cast at least one of the variables to Double:

val success = subscribed.toDouble / Total
//success: Double = 0.11698480458295547

Upvotes: 1

Related Questions