Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Simple formulas to convert weights
Message
 
 
To
06/11/2015 14:22:20
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
General information
Forum:
Science & Medicine
Category:
Mathematics
Miscellaneous
Thread ID:
01627170
Message ID:
01627175
Views:
36
>>Hi everybody,
>>
>>I just spent about 15 minutes googling and could not find simple formulas I need to implement for conversions of kg into pounds or stones and pounds, pounds into the other 2 and stone and pounds into the other two.
>>
>>Here is what I started to write but I can not find the formulas to use:
>>
>>
>> $scope.updateWeight = function(weight1, weight2, units)
>>            {
>>
>>                switch (units) {
>>                    case 'kg':
>>                        $scope.currentGuest.weightG = weight1 * 1000;
>>                        $scope.currentGuest.weight = Math.round(weight1 * 2.20462); // weight in pounds
>>                        $scope.currentGuest.weightStone = Math.round(weight1 * 0.15747); // weight in stones
>>                        $scope.currentGuest.weigthLbs = // remainder for stones/pounds
>>                        break;
>>                    case 'lbs':
>>                        
>>                        break;
>>
>>                    case 'stones': // stones and pounds
>>                        break;
>>                }
>>            }
>
>A metric pound is half a kg? But it's marked as deprecated for ages.

Well, this is what I came up with after looking through various sites and trying to also determine the max limit for all of these:
switch (units) {
                    case 'kg':
                        $scope.currentGuest.weightG = weight1 * 1000;
                        $scope.currentGuest.weight = Math.round(weight1 * 2.20462); // weight in pounds
                        $scope.currentGuest.weightStone = Math.round(weight1 * 0.15747); // weight in stones
                        $scope.currentGuest.weightLbs = Math.round(weight1 * 2.20462 % 14); // remainder for stones/pounds
                        break;
                    case 'lbs':
                        $scope.currentGuest.weightG = Math.round(weight1 * 453.592);
                        $scope.currentGuest.weightKg = weight1 * 0.453592;
                        $scope.currentGuest.weightStone = Math.round(weight1 / 14);
                        $scope.currentGuest.weightLbs = Math.round(weight1 % 14);
                        break;

                    case 'stones': // stones and pounds

                        $scope.currentGuest.weight = weight1 * 14 + weight2;
                        $scope.currentGuest.weightG = Math.round($scope.currentGuest.weight * 453.592);
                        $scope.currentGuest.weightKg = $scope.currentGuest.weight * 0.453592;
                        break;
                }
and on the page markup:
<div class="form-group row">
        <label class="col-md-2 control-label" title="@Labels.weight">@Labels.weight</label>
        <div class="controls" ng-show="showWeightKg">
            <div class="col-md-2 col-lg-2">
                <input type="number" class="form-control"
                       data-sm:number-format data-sm:number ng-show="showWeightKg"
                       min="0.00" max="600.00" name="weightKg" id="weightKg"
                       ng-change="changeWeightKgHappened()"
                       ng-model="currentGuest.weightKg" />
            </div>
            <label class="col-md-1" title="Kg.">Kg.</label>
            <div class="field-validation-error">
                <span ng-show="(form.editGuestGeneralForm.weightKg.$error.min || form.editGuestGeneralForm.weightKg.$error.max) && form.editGuestGeneralForm.weightKg.$dirty">
                    @String.Format(Messages.mustBeBetweenXandY, Labels.weight, 0.00, 600.00)
                </span>
            </div>
        </div>

        <div class="controls" ng-show="showWeight">
            <div class="col-md-2 col-lg-2">
                <input type="number" class="form-control"
                       data-sm:number-format data-sm:number ng-show="showWeight"
                       min="0" max="1500" name="weight" id="weight"
                       ng-model="currentGuest.weight"
                       ng-change="changeWeightHappened()" />
            </div>
            <label class="col-md-1" title="Lbs.">Lbs.</label>

            <div class="field-validation-error">
                <span ng-show="(form.editGuestGeneralForm.weight.$error.min || form.editGuestGeneralForm.weight.$error.max) && form.editGuestGeneralForm.weight.$dirty">
                    @String.Format(Messages.mustBeBetweenXandY, Labels.weight, 0, 1500)
                </span>
            </div>          
        </div>

        <div class="controls" ng-show="showWeightStone">
            <div class="col-md-2 col-lg-2">
                <input type="number" class="form-control"
                       data-sm:number-format data-sm:number ng-show="showWeightStone"
                       min="0" max="100" name="weightStone" id="weightStone"
                       ng-model="currentGuest.weightStone"
                       ng-change="changeWeightStoneHappened()" />
            </div>
            <label class="col-md-1" title="St.">St.</label>

            <div class="field-validation-error">
                <span ng-show="(form.editGuestGeneralForm.weightStone.$error.min || form.editGuestGeneralForm.weightStone.$error.max) && form.editGuestGeneralForm.weightStone.$dirty">
                    @String.Format(Messages.mustBeBetweenXandY, Labels.weight, 0, 100)
                </span>
            </div>
            <div class="col-md-2 col-lg-2">
                <input type="number" class="form-control"
                       data-sm:number-format data-sm:number ng-show="showWeightStone"
                       min="0" max="13" name="weightLbs" id="hweightLbs"
                       ng-model="currentGuest.weightLbs"
                       ng-change="changeWeightStoneHappened()" />
            </div>
            <label class="col-md-1" title="Lbs.">Lbs.</label>
            <div class="field-validation-error">
                <span ng-show="(form.editGuestGeneralForm.weightLbs.$error.min || form.editGuestGeneralForm.weightLbs.$error.max) && form.editGuestGeneralForm.weightLbs.$dirty">
                    @String.Format(Messages.mustBeBetweenXandY, Labels.weight, 0, 13)
                </span>
            </div>
        </div>
Will be testing these now.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform