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
mindus
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

 

Please use plain text.
Developer
simon_hain
Posts: 15,876
Registered: ‎07-29-2008
My Device: Z10 LE
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
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Convert float to String in blackberry

Pass 1 and remove the last 2 characters?

Please use plain text.
Developer
noahhuang
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

Please use plain text.