【问题标题】:How can I cast from double to int in jstl?如何在 jstl 中从 double 转换为 int?
【发布时间】:2022-01-30 06:50:50
【问题描述】:

这是我的 jstl 版本

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

我想像在 Java 中一样从 double 转换为 int。

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

但我抓住了

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

【问题讨论】:

    标签: java jsp jstl el


    【解决方案1】:

    JSTL ...或更准确地说是EL ...不支持Java显式类型转换语法。

    但是在这种情况下,您应该能够像这样实现您想要的结果:

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

    intValue() 方法给出的值与 原始缩小 转换的值相同...这正是转换为 int 所做的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      相关资源
      最近更新 更多