Tag: 共享首选项

如何强制小数点后的两位数

我有以下TextView,它始终显示$ 0.00,除非在单击按钮并保存到此TextView后进行任何计算。 当我运行应用程序时,它显示$ 0.0(这将起作用,除了我正在使用美元和美分,我希望它显示小数后的两位数,除非两个数字都是00) 我正在使用SharedPreferences ,这是我在应用程序中的代码: onCreate() float totalTollAmount = 0; tollAmount = (EditText) mFrame2.findViewById(R.id.etToll); //where the amount is entered tollAmount.setFilters(new InputFilter[] {new DecimalFilter(6, 2)}); tvTotalAmountLabel = (TextView) mFrame2.findViewById(R.id.tvTotalAmount); //holding total amount if (Float.toString(prefs.getFloat(“dblTollAmount”, 0)) != “0.0”) { tollAmount.setText(Float.toString(prefs.getFloat(“dblTollAmount”, 0))); } tvTotalAmountLabel.setText(“$” + Float.toString(prefs.getFloat(“totalTollAmount”, 0))); //retrieves the total toll amount and displays btnCalc.setOnClickListener(new View.OnClickListener() { […]