title: Round double values and cast as integers
body: <p>I have a data frame in PySpark like below. </p>
  
  <pre><code>import pyspark.sql.functions as func
  
  df = sqlContext.createDataFrame(
          [(0.0, 0.2, 3.45631),
           (0.4, 1.4, 2.82945),
           (0.5, 1.9, 7.76261),
           (0.6, 0.9, 2.76790),
           (1.2, 1.0, 9.87984)],
           ["col1", "col2", "col3"])
  
  df.show()
  +----+----+-------+ 
  |col1|col2|   col3|
  +----+----+-------+
  | 0.0| 0.2|3.45631| 
  | 0.4| 1.4|2.82945|
  | 0.5| 1.9|7.76261| 
  | 0.6| 0.9| 2.7679| 
  | 1.2| 1.0|9.87984| 
  +----+----+-------+
  
  # round 'col3' in a new column:
  df2 = df.withColumn("col4", func.round(df["col3"], 2))
  df2.show()
  
  +----+----+-------+----+
  |col1|col2|   col3|col4|
  +----+----+-------+----+
  | 0.0| 0.2|3.45631|3.46|
  | 0.4| 1.4|2.82945|2.83|
  | 0.5| 1.9|7.76261|7.76|
  | 0.6| 0.9| 2.7679|2.77|
  | 1.2| 1.0|9.87984|9.88|
  +----+----+-------+----+
  </code></pre>
  
  <p>In the above data frame <code>col4</code> is <code>double</code>. Now I want to convert <code>col4</code> as <code>Integer</code></p>
  
  <pre><code>df2 = df.withColumn("col4", func.round(df["col3"], 2).cast('integer'))
  
  +----+----+-------+----+
  |col1|col2|   col3|col4|
  +----+----+-------+----+
  | 0.0| 0.2|3.45631|   3|
  | 0.4| 1.4|2.82945|   2|
  | 0.5| 1.9|7.76261|   7|
  | 0.6| 0.9| 2.7679|   2|
  | 1.2| 1.0|9.87984|   9|
  +----+----+-------+----+
  </code></pre>
  
  <p>But I want to round the <code>col4</code> values to nearest</p>
  
  <p><code>expected result</code></p>
  
  <pre><code>+----+----+-------+----+
  |col1|col2|   col3|col4|
  +----+----+-------+----+
  | 0.0| 0.2|3.45631|   3|
  | 0.4| 1.4|2.82945|   3|
  | 0.5| 1.9|7.76261|   8|
  | 0.6| 0.9| 2.7679|   3|
  | 1.2| 1.0|9.87984|  10|
  +----+----+-------+----+
  </code></pre>
  
  <p>How can I do that?</p>