view raw
דור עזרא דור עזרא - 1 year ago 76
Java Question

Put point in string value (android java)

I have BMI calculator app that takes some input and puts it in "EditText". Here is what I am trying to do:

If the input is

, it will become

If the input is
, it will not change.

This is the code I have:

String weight = editText.getText().toString();

jgm jgm

Cant you convert the string to an integer and take modulus 100 to the cms and divide by 100 to get in meters?

You can convert the String weight to int like this

int wgt = Integer.parseInt(weight); 

Then separating meters and centimetres.

int mtrs = wgt / 100; 
int cms = wgt % 100; 

Then combining both

String result = mtrs + "." + cms;