TextView.setText(XMLdata.get("XMLField") + " mm");

input values that are expressed in an abbreviated way:

10,5858555966668 (with comma)

Which I would like to convert into:

10,58
有帮助吗?

解决方案

if your XMLdata.get("XMLField") value is float u can do the following code

String finalValue = String.format(
                    "%.2f", XMLdata.get("XMLField"));

TextView.setText(finalValue + " mm");

if your XMLdata.get("XMLField") is String convert it into float do the above method.

其他提示

TextView.setText((Math.floor(MathXMLdata.get("XMLField") * 100.0) / 100.0).toString() + " mm");

This converts 10,5858555966668 to 1058,58555966668, rounds it to 1058 and converts it back to 10,58.

Note: Math.floor always rounds down (cuts off all missing fractional numbers). If you intend to round to the closest value, use Math.round.

Thank you, thank you very much rmkrishna and Faro ((= I do it with

TextView.setText(String.format("%.2f",Double.parseDouble(XMLData.get("Son7GunlukSagis").replace(",", ".")))+ " mm");

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top