Android 对 ListView 的项目使用 NumberFormat

标签 android string floating-point exponent

我在 Edittext 中有一个字符串,我将其转换为这样的 float :

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”

提前致谢!

最佳答案

检查此链接的格式

http://download.oracle.com/javase/tutorial/i18n/format/decimalFormat.html

试试这个

float val = facture.getFloat(facture.getColumnIndexOrThrow("montant_fa"));

NumberFormat nf = NumberFormat.getNumberInstance(loc);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern(pattern);
String output = df.format(value);
etMontantFac.setText(output);

关于Android 对 ListView 的项目使用 NumberFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7416999/

相关文章:

python - 在 python-numpy 中定义自定义 float8 并从/到 float16 转换?

JavaScript:整数正则表达式捕获 float 的小数部分

javascript - Math.pow() float 作为指数

Android API 请求队列

android - Logcat 中显示的时间

javascript - 如何正确断言 Number.prototype.toLocaleString ("sv-SE") 返回的值?

c - 需要创建一个返回 int 的函数,该函数基于哪个 char 参数具有更多大写字母

android - 如何在 Kotlin 中为 Any 类型声明扩展 val

java - 如何将一个类的 "Context"使用到另一个类中 - Android

Android存储字符串数组