Zakhar Borisov
Zakhar Borisov

Reputation: 39

How can I cast from double to int in jstl?

This is my jstl version

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

I want to cast from double to int like in Java.

${(int)(Math.toDegrees(city.latitude))}

But I catch

[javax.el.ELException: Failed to parse the expression [${(int)(Math.toDegrees(city.latitude))}]] with root cause

Upvotes: 0

Views: 1156

Answers (1)

Stephen C
Stephen C

Reputation: 718678

JSTL ... or more precisely EL ... does not support Java explicit type cast syntax.

But in this case you should be able to achieve the result that you want like this:

${Double.valueOf(Math.toDegrees(city.latitude)).intValue()}

The intValue() method gives the same value as a primitive narrowing conversion ... which is precisely what casting to int would do.

Upvotes: 1

Related Questions