Dber
Dber

Reputation: 21

Android Studio using , insted of . after formatting string

Im trying to make a calculator, but after i've formatted the text im getting the output in XX,XX insted of XX.XX which makes the program crash when reusing the number.

My code is:

                tempX = Double.parseDouble(xText.getText().toString());
                //tempY = Double.parseDouble(yText.getText().toString());
                tempA = Double.parseDouble(aText.getText().toString());
                tempB = Double.parseDouble(bText.getText().toString());


                tempY = tempA * tempX + tempB;
                yText.setText(String.format("%.2f", tempY));

Upvotes: 1

Views: 35

Answers (1)

ArteFact
ArteFact

Reputation: 537

Just use

String.format(Locale.US, "%.2f", tempY);

Upvotes: 1

Related Questions