0

I'm creating a currency converting app. I want get answer in two decimal point.

Here is my code :-

public class MainActivity extends AppCompatActivity {

    public void pri (View view){

        EditText amount = findViewById(R.id.amount);

        Double amout =  Double.parseDouble(amount.getText().toString());

        Double samount = amout * 180;


        Toast.makeText(MainActivity.this, "S. " + rsamount.toString(), Toast.LENGTH_SHORT).show();

        Log.i("price", amount.getText().toString());

    }

Thanks!

dbush
  • 205,898
  • 23
  • 218
  • 273

2 Answers2

1

here is the function in kotlin to convert number in two decimal point.

fun roundOffDecimal(number: Double): Double? {
        val df = DecimalFormat("#.##")
        df.roundingMode = RoundingMode.CEILING
        return df.format(number).toDouble()
    }
Parth
  • 791
  • 7
  • 17
1

Try this

EditText amount = findViewById(R.id.amount);

int amout =  Integer.parseInt(amount.getText().toString());

int samount = amout * 180;

String converted = new DecimalFormat("0.00").format(samount);
Bad Boy
  • 381
  • 2
  • 14