Search code examples
javahtmljspjstlatg

Floating point rounding error using JSTL formatNumber via curl


From Oracle Commerce Platform ATG 11.2, when I hit the JBOSS server I'm getting a different result between a web browser request and curl - it's like the formatNumber is disregarded, and values suffer from floating point roundoff errors.

<span itemprop="price-currency" content="USD">$</span>

<span itemprop="price" class="selection-price">
    <fmt:formatNumber type="currency"
                      pattern="##0.00;"
                      value="${selectionItem.listPriceAmount}"/>
</span>

With 100% consistency, hitting a page in a browser will result in formatted values, such as:

  • $27.99
  • $20.00
  • $10.00

However, an issue was noticed when Google crawled the site, which is 100% reproducible simply via curl of the same page. Those same values appear as:

  • $27.990000000000002
  • $20.0
  • $10.0

There's no user agent logic built-in, just the JSTL formatNumber.

Any idea why the exact same path through the exact same JSP would yield different results?


Solution

  • fmt:formatNumber bypasses type and pattern attributes when it cannot determine a locale. This is documented in the JSTL spec:

    If this action fails to determine a formatting locale, it uses Number.toString() as the output format.

    See section 9.2 Formatting Locale for how to control locale resolution.

    Try setting header accept-language when using curl.