質問

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