Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I round a positive and negative decimal in JSTL?

I have two numbers that I need to round to 4 decimal places in JSTL. One is positive:

40.7615811
40.7616

and the other is negative:

-73.9940841
-73.9941

Both need to be rounded to 4 decimal places, as on the second line of each example.

Is there a clean way to do this in JSTL or do I need to do this in a controller class or JSP scriptlet?

like image 561
nickl Avatar asked Dec 22 '22 23:12

nickl


1 Answers

You can use the formatNumber tag in the fmt (http://java.sun.com/jsp/jstl/fmt) namespace.

For example

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<fmt:formatNumber value="${foo}" pattern="0.0000"/>
like image 173
Jon Freedman Avatar answered Jan 07 '23 19:01

Jon Freedman