Android Question converting inches to feet and inches, pounds to stones and pounds!

Colin Evans

Active Member
Licensed User
Longtime User
Hi, a bit of old school maths, i am presented with a measurement in inches and wish to show it in feet and inches, i.e. 64" shown as feet and inches would be 5' 4" for those too young to remember imperial measurements there's 12 inches in a foot

Similarly I want to convert lbs (pounds) into Stones and pounds, again if I have 147lbs that would be 10st 7lbs, as there's 14lbs in a stone

I've tried dividing it by 12 or 14 but it gives a decimal figure, i.e 64 / 12 = 5.333333 whereas I want to know how many feet (5) and what the remainder is (4), is there a way of doing such a calculation in B4A
 

angel_

Well-Known Member
Licensed User
Longtime User
Maybe this:

B4X:
    Dim Number As Double = 64 / 12
    Log($"${Floor(Number)} feet, ${Round(12 * (Number - Floor(Number)))} inches"$)
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Just needs slight formatting .. as it logs 5.0 feet.

B4X:
Log($"${NumberFormat(Floor(Number), 0, 0)} feet, ${Round(12 * (Number - Floor(Number)))} inches"$)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I've tried dividing it by 12 or 14 but it gives a decimal figure
Don’t use Float/Double. Use Int or Long
what the remainder is
Use the Mod operator
B4X:
Dim totalInches As Int = 64
Dim feet As Int = totalInches / 12
Dim inches As Int = totalInches Mod 12
Log($”${totalInches} inches = ${feet}” ${inches}’”$)
Notes:
Untested, answer typed out on a phone
Since I used a phone, quotes may not copy correctly (if attempting to copy and paste code)
 
Upvote 0
Top