You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Martin Cooper <ma...@tumbleweed.com> on 2002/04/27 07:40:47 UTC

Bugs in and ?

The first bug relates to parsing failures. If I set my machine to believe
it's French and use the following tag:

<fmt:formatNumber value="1001.02" />

the result is "1 001,02", as expected. Now, if I try to parse the same
string (with my machine still believing it's French) using this:

<fmt:parseNumber value="1 001,02" />

the result is "1". Obviously, it didn't work correctly. Even if I use this:

<fmt:parseNumber value="1 001,02" parseLocale="fr_FR" />

I get the same result (i.e. "1").

This is with the 4/26 nightly build running on JDK 1.4.0.

The second bug is more a bug of omission, I believe, although it seems quite
serious to me. On the other hand, it's quite possible that I'm simply
missing the obvious.

While I can use the 'parseLocale' attribute of the <fmt:parseNumber> to
parse a number from any locale (assuming I know the correct locale), there
appears to be no way to format a number for any locale (short of switching
my machine's locale). I would have expected a 'locale' attribute on the
<fmt:formatNumber> tag to allow me to do this.

Just as an example, I'd like to be able to output the following using JSTL:

-----
Numbers are formatted differently in different parts of the world. For
example, the number 1001.02 is formatted as "1,001.02" in England, but as "1
001,02" in France.
-----

I don't see a way of doing this (dynamically, I mean) without a 'locale'
attribute on the <fmt:formatNumber> tag.

Thanks!

--
Martin Cooper



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Bugs in and ?

Posted by Martin Cooper <ma...@tumbleweed.com>.
----- Original Message -----
From: "Shawn Bayern" <ba...@essentially.net>
To: "Tag Libraries Developers List" <ta...@jakarta.apache.org>
Sent: Saturday, April 27, 2002 6:58 AM
Subject: Re: Bugs in <fmt:formatNumber> and <fmt:parseNumber>?


> On Fri, 26 Apr 2002, Martin Cooper wrote:
>
> > The first bug relates to parsing failures. If I set my machine to
believe
> > it's French and use the following tag:
> >
> > <fmt:formatNumber value="1001.02" />
> >
> > the result is "1 001,02", as expected.
>
> Interesting.  That's *not* expected; it should output "1.001,02" for
> fr_FR.  Are you sure it output a space?  The parsing errors follow from
> that.

Yes, I'm sure it's a space. What's more, I've discovered that this isn't
actually the source of the parsing errors. It's much weirder than that. ;-}

There are two ways to use <fmt:parseNumber>:

<fmt:parseNumber value="1 001,02" />
<fmt:parseNumber>1 002,02</fmt:parseNumber>

The first form is what I've been using up until now, and it doesn't work
(regardless of whether 'value' is a literal or an expression). However, the
second form *does* work, and parses the French number (space and all) back
into 1001.02.

>
> > The second bug is more a bug of omission, I believe, although it seems
> > quite serious to me. On the other hand, it's quite possible that I'm
> > simply missing the obvious.
> >
> > While I can use the 'parseLocale' attribute of the <fmt:parseNumber>
> > to parse a number from any locale (assuming I know the correct
> > locale), there appears to be no way to format a number for any locale
> > (short of switching my machine's locale). I would have expected a
> > 'locale' attribute on the <fmt:formatNumber> tag to allow me to do
> > this.
> > [...]
> > I don't see a way of doing this (dynamically, I mean) without a 'locale'
> > attribute on the <fmt:formatNumber> tag.
>
> You can use the <fmt:setLocale> tag to change the locale manually.  I'm
> not sure I remember why <fmt:formatNumber> doesn't have a 'formatLocale'
> attribute; I'd guess it has to do with potential use cases and an attempt
> to keep the tags simpler.  Jan can probably answer questions about the
> i18n library in more detail.

Thanks. I'll give <fmt:setLocale> a shot.

--
Martin Cooper


>
> --
> Shawn Bayern
> "JSP Standard Tag Library"   http://www.jstlbook.com
> (coming this summer from Manning Publications)
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Bugs in and ?

Posted by Shawn Bayern <ba...@essentially.net>.
On Fri, 26 Apr 2002, Martin Cooper wrote:

> The first bug relates to parsing failures. If I set my machine to believe
> it's French and use the following tag:
> 
> <fmt:formatNumber value="1001.02" />
> 
> the result is "1 001,02", as expected. 

Interesting.  That's *not* expected; it should output "1.001,02" for
fr_FR.  Are you sure it output a space?  The parsing errors follow from
that.

> The second bug is more a bug of omission, I believe, although it seems
> quite serious to me. On the other hand, it's quite possible that I'm
> simply missing the obvious.
> 
> While I can use the 'parseLocale' attribute of the <fmt:parseNumber>
> to parse a number from any locale (assuming I know the correct
> locale), there appears to be no way to format a number for any locale
> (short of switching my machine's locale). I would have expected a
> 'locale' attribute on the <fmt:formatNumber> tag to allow me to do
> this.
> [...]
> I don't see a way of doing this (dynamically, I mean) without a 'locale'
> attribute on the <fmt:formatNumber> tag.

You can use the <fmt:setLocale> tag to change the locale manually.  I'm
not sure I remember why <fmt:formatNumber> doesn't have a 'formatLocale'
attribute; I'd guess it has to do with potential use cases and an attempt
to keep the tags simpler.  Jan can probably answer questions about the
i18n library in more detail.

-- 
Shawn Bayern
"JSP Standard Tag Library"   http://www.jstlbook.com
(coming this summer from Manning Publications)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>