1

次のように float に変換する Editext に String があります。

float montantFac = Float.valueOf(etMontantFac.getText().toString());

それをデータベースに保存し、後で DB から取得して、この 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」です。

前もって感謝します!

4

2 に答える 2

2

形式については、このリンクを確認してください

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);
于 2011-09-14T13:39:08.560 に答える
0

これが古いことは知っていますが、誰かが同じことをしようとした場合に備えて、sqlite と listview の間のフォーマット データをここに示します。同様の問題があり、それで解決しました。

これが私の例です

adapter = new SimpleCursorAdapter(....);
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
               if (columnIndex == cursor.getColumnIndex("columnname")) {
                   TextView tv = (TextView) view;
                   NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
                   tv.setText(nf.format(cursor.getInt(columnIndex)));
                   // must return true to be applied
                   return true;
               }
               return false;
        }
});
于 2015-03-05T03:15:25.243 に答える