Skip to content

Instantly share code, notes, and snippets.

@bekzod
Last active February 5, 2016 08:53
Show Gist options
  • Save bekzod/be453e7a99971794d00b to your computer and use it in GitHub Desktop.
Save bekzod/be453e7a99971794d00b to your computer and use it in GitHub Desktop.
format-currency
import Ember from 'ember';
const rates = {
'usd-gbp': 0.6666
}
const formatters = {
gbp(val){
return (Math.ceil(val / 5) * 5).toLocaleString();
}
}
export function formatCurrency([val, toCurrency='gbp', fromCurrency='usd']) {
let rate = rates[fromCurrency + '-' + toCurrency];
let formatter = formatters[toCurrency];
if (val && rate) {
let converted = val * rate;
if (formatter) {
return formatter(converted)
} else {
return converted;
}
}
return val;
}
export default Ember.Helper.helper(formatCurrency);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment