Converting String to Double in Android

前端 未结 8 678
感情败类
感情败类 2020-12-09 02:29

Trying to get double values from an EditText and manipulate them before passing them to another Intent. Not using primitive data type so I can use toString methods.

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 03:11

    i have a similar problem. for correct formatting EditText text content to double value i use this code:

    try {
            String eAm = etAmount.getText().toString();
            DecimalFormat dF = new DecimalFormat("0.00");
            Number num = dF.parse(eAm);
            mPayContext.amount = num.doubleValue();
        } catch (Exception e) {
            mPayContext.amount = 0.0d;
        }
    

    this is independet from current phone locale and return correct double value.

    hope it's help;

提交回复
热议问题