Bug 36328 - fmt:formatNumber ignores maxFractionDigits
Summary: fmt:formatNumber ignores maxFractionDigits
Status: RESOLVED INVALID
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: 1.1
Hardware: All All
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL: http://webtuitive.com/samples/locale.jsp
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-23 20:13 UTC by Hassan Schroeder
Modified: 2005-12-09 10:36 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hassan Schroeder 2005-08-23 20:13:09 UTC
In the absence of an explicit locale setting, fmt:formatNumber ignores the
maxFractionDigits attribute.

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

<c:set var="someCount" value="61"/>
<c:set var="counter1">
<fmt:formatNumber type="number"
    maxFractionDigits="0" value="${ someCount / 3 }"/></c:set>

${counter1}
|
<fmt:setLocale value="en_US"/>
<c:set var="counter2">
<fmt:formatNumber type="number"
    maxFractionDigits="0" value="${ someCount / 3 }"/></c:set>

${counter2}
--------------------------------------------------------------------

Most browsers will show
 20 | 20

but user-agents not providing a Locale via an Accept-Language header
like wget (and Amaya) retrieve

 20.333333333333332 | 20

If I manually add a header to wget, e.g.
   wget --header='Accept-Language: en-us,en'
then the result is '20 | 20' 

demonstration environment: Sun JDK 1.5.0_03 and JSTL 1.1.2
Comment 1 Pierre Delisle 2005-12-09 07:46:10 UTC
The spec says the following:

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

This explains why the maxFractionDigits attribute is ignored.
Comment 2 Pierre Delisle 2005-12-09 19:36:25 UTC
An RFE has been files with the JSTL spec. See:
https://jstl-spec-public.dev.java.net/issues/show_bug.cgi?id=23