Last active
February 5, 2016 08:53
-
-
Save bekzod/be453e7a99971794d00b to your computer and use it in GitHub Desktop.
format-currency
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
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