本文介绍了J2ME - 数字格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在J2ME中格式化十进制数字,就像java 。我看到了一个选项来端口 / / 。
您能否建议准备好使用实现或库?
谢谢!
解决方案
桌面Java实现::
String [] patterns = new String [] {#,#00.00#,0.0;(0.0),
0 。### E0};
DecimalFormat格式=(DecimalFormat)DecimalFormat
.getNumberInstance();
double value = -12.321;
for(int i = 0; i String pattern = patterns [i];
format.applyPattern(pattern);
String text =Pattern:+ pattern
+Sample:+ format.format(value)+\\\
;
add(new LabelField(text));
}
I need to format decimal numbers with patterns in J2ME just like java DecimalFormat.
I see an option to port Format/NumberFormat/DecimalFormat.
Can you suggest ready to use implementation or library?
Thanks!
解决方案
So, I've manage to port desktop java implementation: bbnumberformat:
String[] patterns = new String[] { "#,#00.00#", "0.0;(0.0)",
"0.###E0" };
DecimalFormat format = (DecimalFormat) DecimalFormat
.getNumberInstance();
double value = -12.321;
for (int i = 0; i < patterns.length; i++) {
String pattern = patterns[i];
format.applyPattern(pattern);
String text = "Pattern: " + pattern
+ " Sample: "+format.format(value)+"\n";
add(new LabelField(text));
}
alt text http://img220.imageshack.us/img220/6245/9000.jpg
这篇关于J2ME - 数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!