Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

DecimalFormat

I think we can't use that class... do you know how to format numbers to a certain number of decimal places?
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: DecimalFormat

Check net.rim.device.api.i18n.MessageFormat class

 

It is compatible with J2SE MessageFormat class:

 

http://java.sun.com/j2se/1.3/docs/api/java/text/MessageFormat.html

Developer
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

Re: DecimalFormat

Thanks for your answer. I'm trying to format a Double and get 5 decimal precision, but it doesn't seem to work, i don't get anything... i'm doing this... 

 

    MessageFormat mf = new MessageFormat("{#.#####}");
    Object[] objLa = {new Double(latitud)};
    String latitudF = mf.format(objLa);

 

Any ideas?

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: DecimalFormat

Check this link for custom formatting methods:

 

http://www.horstmann.com/corejava/Format.java

Developer
Posts: 86
Registered: ‎07-21-2009
My Device: Not Specified

Re: DecimalFormat

The link you ref (horstmann...) is for non-commercial use only.

I need this functionality for a commercial app. 

Any links, tips, pointers? 

thanks!

lucidbee

New Developer
Posts: 4
Registered: ‎10-19-2009
My Device: Not Specified

Re: DecimalFormat

It seems that the MessageFormat class does not yet support numbers...See this post:

 

http://supportforums.blackberry.com/t5/Java-Development/Formatting-a-floating-point-number/m-p/31590...

Developer
Posts: 64
Registered: ‎05-09-2009
My Device: Not Specified

Re: DecimalFormat

It's really crappy RIM does not support these standard Java libraries, this makes development often very frustrating. When i look at the Android libraries for example it's just there.

Developer
Posts: 62
Registered: ‎01-22-2010
My Device: BOLD 9700
My Carrier: Globe

Re: DecimalFormat

hi ibarrera, what did you do to achieve Decimal formatting?