【问题标题】:How to set thousands seperators with two decimal places?如何设置带两位小数的千位分隔符?
【发布时间】:2013-04-26 08:50:28
【问题描述】:

在我的应用程序中,我限制用户输入 7.2 位数字(如 1234567.12)。输入时应显示为 1,234,567.12。但它必须在数据库中保存为 1234567.12。我使用十进制格式为“### ,###.##" 显示在编辑文本框中。但是使用浮点数解析时出错,同时保存在数据库中。请告诉我任何建议。

关于格式化,我正在使用这个格式化程序 _decimalFormat =new DecimalFormat("###,###,###.##");

        _decimalFormat.setMinimumFractionDigits(2);
        _decimalFormat.setMaximumFractionDigits(2);

在 ontextChanged 监听器中,保存在数据库中时,我在这一行中遇到错误 [amountText2.setText(Float.parseFloat(amountText1.getText().toString()));]

【问题讨论】:

  • 你的代码是什么?你的错误是什么?

标签: android android-edittext number-formatting


【解决方案1】:

删除EditText 包含的字符串中的逗号并将其解析为浮点数。从上面的代码中,它应该是这样的:

amountText1.getText().toString().replace(",", "")

在这里,您将逗号替换为空字符串,这与删除它们几乎相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 2011-07-16
    • 1970-01-01
    • 2016-01-16
    相关资源
    最近更新 更多