Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to input zero after decimal point in Android EditText
    primarykey
    data
    text
    <p>I have an Android EditText which when a user puts a number, it edits the number and adds thousand separators using Decimal Format, but when one is inputting floating point numbers, i does not add zeros after the decimal point. so i can not input 1.000000008 because the zeros won't go on but other numbers do. Is there any java DecimalFormat pattern that will allow a user to input a zero after the decimal point? Here's the code for my EditText.</p> <pre><code>am = new TextWatcher(){ public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.toString().contains(String.valueOf(df.getDecimalFormatSymbols().getDecimalSeparator()))) { hasFractionalPart = true; } else { hasFractionalPart = false; } } public void afterTextChanged(Editable s) { amount.removeTextChangedListener(this); amount2.setText(s.toString()); try { int inilen, endlen; inilen = amount.getText().length(); String v = s.toString().replace(String.valueOf(df.getDecimalFormatSymbols().getGroupingSeparator()), ""); Number n = df.parse(v); value = Double.parseDouble(v); int cp = amount.getSelectionStart(); if (hasFractionalPart) { amount.setText(df.format(n)); } else { amount.setText(dfnd.format(n)); } endlen = amount.getText().length(); int sel = (cp + (endlen - inilen)); if (sel &gt; 0 &amp;&amp; sel &lt;= amount.getText().length()) { amount.setSelection(sel); } else { // place cursor at the end? amount.setSelection(amount.getText().length() - 1); } } catch (NumberFormatException nfe) { // do nothing? } catch (ParseException e) { // do nothing? } amount.addTextChangedListener(this); } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload