简体   繁体   中英

How to use the value returned by formatNumber in a String comparison

I got this line to format a number :

<fmt:formatNumber type="number" pattern="###,#######" value="1234567890" var="test"/>

Above line output 123 4567890 with my current locale (french).

If I use below code :

<c:set var="ref" value="123 4567890"/> ${ref == test}

It return false, why?

First, I thought that test was no a String hence I tried that :

<c:set var="test2" value="${test}"/>

But ${ref == test2} still return false.

Looks like the French locale uses a non-breaking space character (the "&nbsp", hex 0xA0 (160 decimal)), but you were using a regular space (character 32)

This should print true :

<fmt:formatNumber type="number" pattern="###,#######" value="1234567890" var="test"/>
<% pageContext.setAttribute("nbsp", String.valueOf('\u00a0'));%>
<c:set var="ref" value="123${nbsp}4567890"/>
ref is ${ref} <br />
test is ${test} <br />
${ref == test}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM