Android Number formatting and Convert String to Integer in Android

Hii Developer in this Article I am sharing Android Number formatting and Convert String to Integer in Android. Convert String to integer, and Integer to String, Dobule to String, Type of formating with example.  And also convert a number value 10000 to 10k.

1000 to 1k  
5821 to 5.8k
10500 to 10k
101800 to 101k
2000000 to 2m
7800000 to 7.8m
92150000 to 92m
123200000 to 123m

Number formatting in Android 

public String prettyCount(Number number) {
    char[] suffix = {' ', 'k', 'M', 'B', 'T', 'P', 'E'};
    long numValue = number.longValue();
    int value = (int) Math.floor(Math.log10(numValue));
    int base = value / 3;
    if (value >= 3 && base < suffix.length) {
        return new DecimalFormat("#0.00").format(numValue / Math.pow(10, base * 3)) + suffix[base];
    } else {
        return new DecimalFormat().format(numValue);
    }
}

Create this method and set Convert Value in textView

Total_Step.setText(prettyCount(mSubTotal1));

 

Android Convert String tO Integer And Integer to string.

String MyAge,Weight,height
int Age= Integer.parseInt(MyAge);
int Weight= Integer.parseInt(Weight);
int height= Integer.parseInt(height);

 Integer to String

Int MyAge,Weight,height
String Age= String.valueOf(MyAge);
String Weight= String.valueOf(Weight);
String height= String.valueOf(height);

 

Floating and Double Value to String formating in Android with two-point of Flot value.

double Men_BMR = 88.362 + (13.39 * Weight) + (4.79 * height) - (5.67 * Age);
 BMI_Result.setText(String.format("%.2f",Men_BMR)+" Calories/day");

 

Android How to Get Value For EditText and TextView example

Bmi_Weight = (EditText) findViewById(R.id.Bmi_Weight);
Bmi_height = (EditText) findViewById(R.id.Bmi_height);
Bmi_Age = (EditText) findViewById(R.id.Bmi_Age);


int Age= Integer.parseInt(Bmi_Age.getText().toString().trim());
int Weight= Integer.parseInt(Bmi_Weight.getText().toString().trim());
int height= Integer.parseInt(Bmi_height.getText().toString().trim());

ReadMore Android Tutorial 

You may also like...