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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 128
Registered: ‎11-05-2009
My Device: 9700
My Carrier: 9700

Convert float to String in blackberry

Hi

   I need to set the string value to the editfied. So I want to convert  the float value (with exponent) to string. 

 

So i used Formatter api to handle the exponent and convert to string by the following code.

 

Formatter formatter = new Formatter("en"); 
textBox.setText(formatter.formatNumber(floatValue, 2));

 

But in my requirement i need to pass '0' as decimal value. So when i pass the the decimal value as '0', then the applicaiton is crashing again (illegalargument exception).  Because formatter accepts decimal value as 1 to 15 and not as '0'. But i want to use '0' as decimal value. 

 

Can anybody let me know that anyother way to solve this issue?

 

Thanks

mindus

 

Developer
Posts: 17,026
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Convert float to String in blackberry

I don't understand the requirement to pass '0' as decimal value.
parameter:
decimals - the number of decimals to use

getting a result with 0 decimals makes no sense as it would be empty.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Convert float to String in blackberry

Pass 1 and remove the last 2 characters?

Developer
Posts: 100
Registered: ‎10-01-2012
My Device: BB10 Dev Alpha
My Carrier: Roger

Re: Convert float to String in blackberry

[ Edited ]

double value = 0.0;
Formatter fmt = new Formatter("en");
System.out.println(fmt.formatNumber(value, 2));

 

 

you will get   0.00 as a String