I have two functions
function toCents(number) {
number = number.replace("$","");
arr = number.split(".");
arr[0] = parseInt(arr[0]) * 100;
if(arr[1].length === 1){
arr[1] = parseInt(arr[1]) * 10;
}else{
arr[1] = parseInt(arr[1]);
}
number = arr[0] + arr[1];
return number;
}
and
function centsToDollar(cents){
cents = String(cents);
position = cents.length - 2;
return ["$", cents.slice(0,position), ".", cents.slice(position)].join("");
}
is there a place for me to put these functions so that they will be available in every javascript file through out my rails application similar to how helper methods are used?
also is there a more standard way of converting dollars in string form to cents then back to dollar format with javascript?