0

if users input "5" at "akenari" textview and click "altmis" button "bkenari" print 1.66666666√3 but I want print 1.66√3 how can I do?

altmis.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try{
                double sayi1f=Double.parseDouble(akenari.getText().toString());
                bkenari.setText(String.valueOf(sayi1f / 3 + "√3"));
            }catch(NumberFormatException nfe){
            }
        }
Cœur
  • 37,241
  • 25
  • 195
  • 267
user3807062
  • 3
  • 1
  • 4
  • 1
    Possible duplicate of [Best way to Format a Double value to 2 Decimal places](http://stackoverflow.com/questions/8819842/best-way-to-format-a-double-value-to-2-decimal-places) – MartinS Feb 28 '16 at 18:51
  • use `Math.round()` function – Omal Perera Feb 28 '16 at 19:00
  • Possible duplicate of [How to round a number to n decimal places in Java](http://stackoverflow.com/questions/153724/how-to-round-a-number-to-n-decimal-places-in-java) – Roy Falk Feb 28 '16 at 21:09

1 Answers1

0

let your value to be roundoff is x

double x = 1.66666;
double y = Math.round(x*100.0)/100.0;

then y will easily give you the answer

no big logic used here

Omal Perera
  • 2,971
  • 3
  • 21
  • 26
  • i need 1.66√3 , not integer . user input 5 , 8, 11 etc this print x,xxxxxxx√3 but i want only x,xx√3 – user3807062 Feb 28 '16 at 20:17
  • `double num = Math.round((sayi1f / 3)*100.0)/100.0;` `bkenari.setText(String.valueOf( num+ "√3"));` just copy & see it will give 1.66√3 – Omal Perera Feb 28 '16 at 20:26