title: How to round the decimal value to two places using JSTL where the List is created as output from database
body: <p>I'm working on small project where the the sql output (result set) is converted in to list and passed on to JSP to display the data.</p>
  
  <p>How to I round a particular column contents to upto two decimal places. </p>
  
  <p>Here's the code that I have so far:</p>
  
  <p>Passing resultSet to create list:</p>
  
  <pre><code>rs = stmt.executeQuery(sql);
  List&lt;String&gt; output = setData(rs);
  </code></pre>
  
  <p>Setting data:</p>
  
  <pre><code>public List&lt;String&gt; setData(ResultSet rs) throws SQLException {
  
       ResultSetMetaData md = rs.getMetaData();
       int columns = md.getColumnCount();
       ArrayList list = new ArrayList();
       while (rs.next()){
           HashMap row = new HashMap(columns);
           for(int i=1; i&lt;=columns; ++i) {           
               row.put(md.getColumnName(i),rs.getObject(i));
           }
           list.add(row);
       }
       return list;
   }
  </code></pre>
  
  <p>Using the above code in JSP page as shown below:</p>
  
  <pre><code>&lt;%
   String sql = "My SQL code goes here";
   ConnectionFactory cf = new ConnectionFactory();
   List&lt;String&gt; output = cf.getData(sql);
   pageContext.setAttribute("output",output);
  %&gt;
  &lt;tbody&gt;
       &lt;c:forEach items="${output}" var="ls"&gt;
           &lt;tr&gt;
               &lt;td&gt;&lt;c:out value="${ls.col1}"/&gt;&lt;/td&gt;
               &lt;td&gt;&lt;c:out value="${ls.col2}"/&gt;&lt;/td&gt;
               &lt;td&gt;&lt;c:out value="${ls.col3}"/&gt;&lt;/td&gt;
               &lt;td&gt;&lt;c:out value="${ls.col4}"/&gt;&lt;/td&gt;
               &lt;td&gt;&lt;c:out value="${ls.col5}"/&gt;&lt;/td&gt;
           &lt;/tr&gt;
       &lt;/c:forEach&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>Now let's say "ls.col3" has decimal values (which unfortunately I can't restrict at SQL), how to restrict/round the decimals to two places?</p>
  
  <p>Any insight is greatly appreciated :)</p>
  
  <p>Regards,</p>