如何设置 EditText 的数字格式

New*_*ton 2 format android numbers

我希望在我的 EditText 中显示的数字最多为 1 个小数位,没有前导零,例如 25.0 不像 025.0

我怎样才能做到这一点?

这是在安卓中

use*_*305 5

您可以使用 DecimalFormat

DecimalFormat format = new DecimalFormat("##.#");
String formattedText = format.format(025.0);
editText.setText(formattedText);
Run Code Online (Sandbox Code Playgroud)

你会得到结果EditText25.0