本文介绍了在BlackBerry格式十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示双给用户,但它被打印为1.00000000001

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.

推荐答案

有一个类调用格式化,可以做的伎俩。这里有一个code片断:

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);

和,这里给的JavaDoc链接:javax.microedition.global.Formatter

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

这篇关于在BlackBerry格式十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:28