在 JSTL 中将字符串转换为浮点数
Convert String to Float in JSTL
我有一个字段 price
存储为一个字符串,我想在 JSTL 中对这个字段进行操作,有没有办法可以做到这一点?我尝试使用 <fmt:parseNumber var="price" type="currency" value="${item.price}" />
,这似乎给我一个错误 [1],我的价格是 "0"
。我也曾尝试 number
作为类型,但我希望它能转换为 float/double。
[1]
java.text.ParseException: Unparseable number: "0"
at java.text.NumberFormat.parse(NumberFormat.java:385)
at org.apache.taglibs.standard.tag.common.fmt.ParseNumberSupport.doEndTag(ParseNumberSupport.java:164)
知道我可以在这里做什么吗?
我认为对于货币格式,我们需要如下传递货币符号试试这个
<fmt:formatNumber type="currency" currencySymbol="$" value="${product.price}" />
我有一个字段 price
存储为一个字符串,我想在 JSTL 中对这个字段进行操作,有没有办法可以做到这一点?我尝试使用 <fmt:parseNumber var="price" type="currency" value="${item.price}" />
,这似乎给我一个错误 [1],我的价格是 "0"
。我也曾尝试 number
作为类型,但我希望它能转换为 float/double。
[1]
java.text.ParseException: Unparseable number: "0"
at java.text.NumberFormat.parse(NumberFormat.java:385)
at org.apache.taglibs.standard.tag.common.fmt.ParseNumberSupport.doEndTag(ParseNumberSupport.java:164)
知道我可以在这里做什么吗?
我认为对于货币格式,我们需要如下传递货币符号试试这个
<fmt:formatNumber type="currency" currencySymbol="$" value="${product.price}" />