commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <ted.dunn...@gmail.com>
Subject Re: utils to display currency for any bigdecimal
Date Wed, 15 Jul 2009 19:17:50 GMT
As I suggested previously:

    public void testFormatBigDecimal() {
        BigDecimal x = new BigDecimal("12345678.43");
        assertEquals("$12,345,678.43", String.format("$%,.2f", x));
    }


On Wed, Jul 15, 2009 at 11:54 AM, fachhoch <fachhoch@gmail.com> wrote:

>
> I  asking If there is any simpler way to do this right now I doing it
>
> NumberFormat.getCurrencyInstance().format(ObjectUtils.defaultIfNull(stgFinding.getFindingAmt(),
> new BigDecimal(0)))
> NumberFormat.getCurrencyInstance().format   throws exception  if the object
> passed to it is null ,I am aksing if there is anything available with
> commons utils which takes care of this internally ?
>
> Ted Dunning wrote:
> >
> > I find manuals very handy for questions like this:
> >
> >
> http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintWriter.html#printf(java.lang.String,%20java.lang.Object<http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintWriter.html#printf%28java.lang.String,%20java.lang.Object>
> ..
> > .)
> >
> >
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#format(java.lang.String,%20java.lang.Object<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#format%28java.lang.String,%20java.lang.Object>
> ..
> > .)
> >
> >
> >
> > On Wed, Jul 15, 2009 at 10:28 AM, tubin gen <fachhoch@gmail.com> wrote:
> >
> >> Is there any utils to display a bigdecimal with $56,98
> >>  for example is there any utils which takes a bigdecimal , does not
> throw
> >> exception if it is null and if not then formats   to comma seperated
> >> number
> >> with $ symbol before ?
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/utils-to-display-currency-for-any-bigdecimal-tp24502491p24503798.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


-- 
Ted Dunning, CTO
DeepDyve

111 West Evelyn Ave. Ste. 202
Sunnyvale, CA 94086
http://www.deepdyve.com
858-414-0013 (m)
408-773-0220 (fax)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message