views:

1013

answers:

5

I'd like to convert kilos into pounds and ounces e.g. if a user enters 10 kg then the function should return 22 lb and 0.73 oz

Any ideas?

A: 

this is an easy conversion... I will leave the details to you....

1 kilogram = 2.20462262 pounds

Muad'Dib
+2  A: 
function kgToPounds(value) {
    return value * ?conversionValue?;
}

Replace ?conversionValue? to whatever the rate needs to be.

function poundsToOunces(value) {
    return value * 16;
}

Not really hard stuff, this.

Jarrett Meyer
Might not be hard for yourself, for conversions always confuse me thanks :)
Tom
+2  A: 
function KtoLbs(pK) {
  nearExact = pK/0.45359237;
  lbs = Math.floor(nearExact);
  oz = (nearExact - lbs) * 16;
}
/* sigh */
dlamblin
+1  A: 

Based on @dlamblin's answer, here's a function that returns the pounds and ounces in a structure.

function KtoLbs(pK) {
    var nearExact = pK/0.45359237;
    var lbs = Math.floor(nearExact);
    var oz = (nearExact - lbs) * 16;
    return {
        pounds: lbs,
        ounces: oz
    };
}

var imperial = KtoLbs(10);
alert("10 kg = " + imperial.pounds + " lbs and " + imperial.ounces + " oz.");
Matthew Crumley
+2  A: 

Google almost does it. Wont do pounds and ounces.

Google "10 kg in ounces"

Google responds: 10 kilograms = 352.739619 ounces

Then all you'd have to do is write all the plumbing to send the info to google and get it back.

:-)

Paul
That seems like a really expensive way to do it :)
Tom