Wednesday, November 11, 2009

Weight conversion

American medical professionals have dual modes in weight and measurement. When they are at work, they use metric, when they are out of work, they use the old British system that British themselves abandoned. So my baby has a whiteboard that has his weight... and today he is at 2000g! Gee, I failed to comprehend this number. Ok, 1 kg is about 2.2 pounds... 4.4 pounds is 4 lb and how many ounce? Ok, the 16 oz in a pound is not so easy to convert. Sure go to the web you say? They give me decimal pounds, not pound and ounce. Gee I need to write my own code.


<form name="theform">
grams: <input type="text" name="grams">
<input type=button name="btnConvert" value="Convert" onClick="javascript:doConvert()">
<div id="result"></div>
</form>

<script language="Javascript">
//1 gram = 0.0352739619 ounces
function doConvert() {

var ounce = (document.theform.grams.value-0)*0.0352739619;
var lb = Math.floor(ounce / 16)
var remain = Math.round(ounce % 16)

var result = document.getElementById("result");
result.innerHTML = lb + "lb "+remain+" oz"
}
</script>

2 comments:

Jade said...

Oh, I didn't know he's a premie! How is the little guy doing?

Joseph Mak said...

Baby is doing good: right where he should be