Skip to content

Commit

Permalink
Added miles, fixed floats and added more abbreviations.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredefl committed Apr 10, 2013
1 parent da07482 commit a699967
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ function shortMatch ( string ) {
return returnArray;
}

var fpFix = function (n) {
return Math.round(n * 1000000000000000)/1000000000000000;
};

/**
* Processes the user input
*
Expand All @@ -116,7 +120,7 @@ function processInput ( input ) {

if ( result === false ) return; // Show Error

$(".giant-input").val(result.converted + result.outUnit);
$(".giant-input").val(fpFix(result.converted) + result.outUnit);
}

$(document).ready( function () {
Expand Down
13 changes: 13 additions & 0 deletions js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var conversions = [
{unit: "mm", calc: "x * 1000"},
{unit: "in", calc: "x * 0.0254"},
{unit: "ft", calc: "x * 0.3048"},
{unit: "mi", calc: "x / 1.609344"},
{unit: "sm", calc: "x / 0.71"}
]},
{unit: "km", conversions: [
Expand All @@ -27,6 +28,9 @@ var conversions = [
{unit: "ft", conversions: [
{unit: "m", calc: "x / 0.3048"}
]},
{unit: "mi", conversions: [
{unit: "m", calc: "x * 1.609344"}
]},
{unit: "sm", conversions: [
{unit: "m", calc: "x * 0.71"},
{unit: "dsm", calc: "x * 10"},
Expand Down Expand Up @@ -81,6 +85,7 @@ var conversions = [
];

var acronyms = {
// "" : "",
"millimeter" : "mm",
"millimeters" : "mm",
"centimeter" : "cm",
Expand All @@ -89,6 +94,14 @@ var acronyms = {
"meters" : "m",
"kilometer" : "km",
"kilometers" : "km",
"liter" : "l",
"liters" : "l",
"inch" : "in",
"inches" : "in",
"foot" : "ft",
"feet" : "ft",
"mile" : "mi",
"miles" : "mi",
"salmon meter" : "sm",
"salmonmeter" : "sm",
"salmon meters" : "sm",
Expand Down

0 comments on commit a699967

Please sign in to comment.