Android 对 ListView 的项目使用 NumberFormat
我在 Edittext 中有一个字符串,我将其转换为浮点数,如下所示:
float montantFac = Float.valueOf(etMontantFac.getText().toString());
我将其保存在数据库中,稍后,我从数据库取回它,然后再次将其分配给此 EditText。
etMontantFac.setText(facture.getString(facture.getColumnIndexOrThrow("montant_fa")));
我的问题是它显示一些带有指数的数字。 例如,1000000 显示如下:1e+06
我怎样才能只显示数字(没有字母或+或其他任何东西)的值?
编辑:
@Pratik:谢谢,效果很好!
我还需要对 ListView 的项目执行相同的操作,但我不知道如何在这种情况下使用您的解决方案。你能帮助我吗 ?
这是我的 ListView:
private void fillData(){
Cursor cuFactures = db.recupListeFacture(triFactures, argumentWhereVhc, choixVhc, argumentWhereGar, choixGar);
startManagingCursor(cuFactures);
ListAdapter adapter = new SimpleCursorAdapter(this,
R.layout.facture_ligne,
cuFactures,
new String[] {"libelle_fa", "nom_vhc", "montant_fa", "nom_garage", "date_fa"},
new int[] {R.id.listeNomFac, R.id.listeNomVhcFac, R.id.listeMontantFac, R.id.listeNomGarFac, R.id.listeDateFac});
setListAdapter(adapter);
相关字段始终为“montant_fa”
提前谢谢您!
I have a String in an Editext that I convert to a float like this :
float montantFac = Float.valueOf(etMontantFac.getText().toString());
I save it in a database and later, I get it back from the DB and I assign it again to this EditText.
etMontantFac.setText(facture.getString(facture.getColumnIndexOrThrow("montant_fa")));
My problem is that it displays some numbers with exponent.
For example, 1000000 is displayed like this : 1e+06
How can I do to ever display the values with numers only (no letter or + or anything else) ?
EDIT :
@Pratik : Thanks, that works fine!
I also need to do the same for an item of a ListView but I don't find how to use your solution in this case. Can you help me ?
Here is my ListView :
private void fillData(){
Cursor cuFactures = db.recupListeFacture(triFactures, argumentWhereVhc, choixVhc, argumentWhereGar, choixGar);
startManagingCursor(cuFactures);
ListAdapter adapter = new SimpleCursorAdapter(this,
R.layout.facture_ligne,
cuFactures,
new String[] {"libelle_fa", "nom_vhc", "montant_fa", "nom_garage", "date_fa"},
new int[] {R.id.listeNomFac, R.id.listeNomVhcFac, R.id.listeMontantFac, R.id.listeNomGarFac, R.id.listeDateFac});
setListAdapter(adapter);
The concerned field is always "montant_fa"
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查此链接的格式
http://download.oracle.com/javase/ tutorial/i18n/format/decimalFormat.html
尝试这种方式
check this link for format
http://download.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
try this way
我知道这是旧的,但这里是 sqlite 和 listview 之间的格式数据 如果有人试图做同样的事情。我有类似的问题并用它解决了。
这是我的例子
I know this is old, but here is for the format data between sqlite and listview in case someone trying to do the same thing. I had similar problem and solved it with that.
here is my example