title: How to format a column in Spark DataFrame
body: <p>Have a Spark DataFrame call df like this:</p>
  
  <pre><code>+---+---+
  | c1| c2|
  +---+---+
  |  1|  6|
  |  2|  7|
  |  3|  8|
  |  4|  9|
  |  5| 10|
  |  6| 11|
  |  7| 12|
  |  8| 13|
  |  9| 14|
  +---+---+
  </code></pre>
  
  <p>and I want to generate a new DataFrame to get the fraction of c1 and c2, the result should be like this:</p>
  
  <pre><code>+---+---+------+
  | c1| c2|    c3|
  +---+---+------+
  |  9| 14|0.6429|
  |  8| 13|0.6154|
  |  7| 12|0.5833|
  |  6| 11|0.5455|
  |  5| 10|0.5000|
  |  4|  9|0.4444|
  |  3|  8|0.3750|
  |  2|  7|0.2857|
  |  1|  6|0.1667|
  +---+---+------+
  </code></pre>
  
  <p>However, when I use the code </p>
  
  <pre><code>res.withColumn("c3", col("c1")/col("c2")).orderBy(col("c3").desc).show()
  </code></pre>
  
  <p>I got:</p>
  
  <pre><code>+---+---+-------------------+
  | c1| c2|                 c3|
  +---+---+-------------------+
  |  9| 14| 0.6428571428571429|
  |  8| 13| 0.6153846153846154|
  |  7| 12| 0.5833333333333334|
  |  6| 11| 0.5454545454545454|
  |  5| 10|                0.5|
  |  4|  9| 0.4444444444444444|
  |  3|  8|              0.375|
  |  2|  7| 0.2857142857142857|
  |  1|  6|0.16666666666666666|
  +---+---+-------------------+
  </code></pre>
  
  <p>How to format c3 to the desired format without having to generate another DataFrame? (I want to get the result from df in just one line of code, how can i achieve this?)</p>