askIT

Android Cm to feet an inches

Here are algoritms for converting between metric and imperial units. We convert first cm to feet and inches, and then feet and inches to cm. You can insert the algoritms into their own methods. For the cm to feet and inches it is possible to return a string with the answer.

Cm to feet and inches

/* Cm to feet and inches */
double cm = 180;

double doubleFeet = cm/30.48;
int intFeet = (int)doubleFeet;
double inches = (cm/2.54) - (intFeet * 12);
               
Toast.makeText(this, "Cm: " + cm + "\nFeet and inces: " + intFeet + " ft " + inches + " in", Toast.LENGTH_LONG).show();

Feet and inches to cm

/* Feet and inches to cm */
// formula: cm = ((feet * 12) + inches) * 2.54
double feet = 5;
double inches = 3;

double cm = ((feet * 12) + inches) * 2.54;
cm = Math.round(cm);

Toast.makeText(this, "Feet and inces: " + feet + " " + inches + "\nCm: " + cm, Toast.LENGTH_LONG).show();

Add comment

avatar_blank_60.png

Comment:

Name:

Email:

Comments

No comments yet. You can be the first one to comment. Just write your comment in the form and click on the submit button.