Last active
April 28, 2017 14:57
-
-
Save swoleengineer/4142143c97e349bdc22094c37044e37b to your computer and use it in GitHub Desktop.
Angular filter for metric from imperial ({ft + in -> cm}, {lbs -> kg})
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.filter('metric', function(authToken){ | |
return function(input, type, inch) { | |
var isMetric = authToken.getMetric(); | |
if(isMetric) { | |
if(type == 'cm') { | |
if(isNaN(input)) { | |
return 'cm.'; | |
} else { | |
if(inch) { | |
return ((((input * 12) * 1) + (inch * 1)) * 2.54).toFixed(2) + ' cm.'; | |
} | |
else { | |
return ((((input * 12) * 1)) * 2.54).toFixed(2) + ' cm.'; | |
} | |
} | |
} else if(type == 'kg') { | |
if(isNaN(input)){ | |
return 'kg.'; | |
}else{ | |
var amount = 0.453592 * 1; | |
return (((input * amount) / 1 ) * 1).toFixed(2) + ' kg.'; | |
} | |
} | |
} else { | |
if(type == 'kg') { | |
if(isNaN(input)){ | |
return 'lbs.'; | |
}else{ | |
return input + ' lbs.'; | |
} | |
} else if(type == 'cm') { | |
if(isNaN(input)){ | |
return "ft., in."; | |
}else{ | |
return input + "'" + inch + '"'; | |
} | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
authToken.getMetric() detects if the user wants things in metric or not. This is something saved in the user's schema