• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Calculator can't do decimals?

Tarcin

Newbie
I am creating an Algebraic Calculator, and I am running into some problems. I use Eclipse, and someone complained that they couldn't use negative numbers. So I fixed that, but while testing, I noticed that whenever I tried to input a decimal for A, B, or C the application would crash. Can anyone help me? If you guys really need it I wouldn't mind pming my code.

Thanks!
Tarcin
 
I'd like to help out but it's gonna be hard to with such little info given. What do you mean by "A, B or C"?
 
Ar you using an Int value for the number (those can't do decimals)
With double you can have 2 digets behinde the ,)
float is fully open
 
String a = (String)et1.getText().toString();
String b = (String)et2.getText().toString();
String c = (String)et3.getText().toString();
String d = (String)et4.getText().toString();
Int inta = Integer.parseint(a);
Int intb = Integer.parseint(b);;
Int intc = Integer.parseint(c);
Int intd = Integer.parseint(d);
float f1 =(float)((floatb-floata)/(floatd-floatc));
String sx = "Slope= " + f1;
tv6.setText(sx);
 
Ar you using an Int value for the number (those can't do decimals)
With double you can have 2 digets behinde the ,)
float is fully open

Actually doubles can have a lot more decimals. Also doubles are more precise than floats since doubles use 64 bit and floats use only 32 bits.
 
Back
Top Bottom