You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by tubin gen <fa...@gmail.com> on 2009/07/15 19:28:03 UTC

utils to display currency for any bigdecimal

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 ?

Re: utils to display currency for any bigdecimal

Posted by Ted Dunning <te...@gmail.com>.
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 <fa...@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 <fa...@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)

Re: utils to display currency for any bigdecimal

Posted by fachhoch <fa...@gmail.com>.
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/lang/String.html#format(java.lang.String,%20java.lang.Object..
> .)
> 
> 
> 
> On Wed, Jul 15, 2009 at 10:28 AM, tubin gen <fa...@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


Re: utils to display currency for any bigdecimal

Posted by Ted Dunning <te...@gmail.com>.
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/lang/String.html#format(java.lang.String,%20java.lang.Object..
.)



On Wed, Jul 15, 2009 at 10:28 AM, tubin gen <fa...@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 ?
>