My code looks simple and I don't know what is the problem. If I code something like this:
tvResult.setText(sum+ "RUB");
it shows correct numbers. But if I try to add an IF statement like this:
if(sum>=114000) {
tvResult.setText(sum + " RUB");
}
and sum equals, say, 1000000, it shows weird number: 1111111.0. Need your advice =) Thanks in advance
Here is the XML code:
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="@+id/tvCash"
android:layout_below="@id/tvCalculate"
android:hint="@string/cash_money"
android:background="@drawable/zakat_red"
android:layout_marginTop="20dp"/>
<EditText
android:layout_width="130dp"
android:layout_height="40dp"
android:id="@+id/etCash"
android:inputType="numberDecimal"
android:layout_above="@+id/tvBank"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="@string/hint_zakat"
android:gravity="end"
android:imeOptions="actionDone"/>
And Java code:
TextWatcher twCash=new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
tvCash.setBackgroundResource(R.drawable.zakat_green);
sum+=Float.valueOf(etCash.getText().toString());
if(sum>=114000) {
tvResult.setText(sum + " RUB");
}
}
};