Code example for MathContext

0
 
public class NeueUmfrage extends Activity
{ 
	private String getPercent(int opt)
	{ 
		MathContext mc = new MathContext(3);
		if (opt == 0) return (new BigDecimal(100)).divide(new BigDecimal(yes).add(new BigDecimal(no))).multiply(new BigDecimal(no)).round(mc).toString();
		else if (opt == 1) return (new BigDecimal(100)).divide(new BigDecimal(yes).add(new BigDecimal(no))).multiply(new BigDecimal(yes)).round(mc).toString();
		else return "0"; 
	} 
	 
	protected void onCreate(Bundle icicle) 
	{ 
        super.onCreate(icicle);
 
        setContentView(R.layout.neueumfrage);
        final TextView textJa = (TextView) findViewById(R.id.textView1);
        final TextView textNein = (TextView) findViewById(R.id.textView2);
         
 
        final Button ja = (Button) findViewById(R.id.button1);