Mahesh Babu
Mahesh Babu

Reputation: 3433

Format decimal values on a BlackBerry

I am displaying a double to the user, but it is printed as 1.00000000001

However, I need only two digits after the decimal point.

Upvotes: 0

Views: 1203

Answers (2)

Fostah
Fostah

Reputation: 11796

There's a class called Formatter that can do the trick. Here's a code snippet:

double value = 1.24790000001;
Formatter formatter = new Formatter();
String formatted = formatter.formatNumber(value, 2);

And, here's a link to the JavaDoc: javax.microedition.global.Formatter

Upvotes: 8

Adrian Smith
Adrian Smith

Reputation: 17573

Have you looked at String.format e.g.

String x = String.format("%.2f", number);

http://download.oracle.com/javase/6/docs/api/java/lang/String.html

Upvotes: -4

Related Questions