Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function currencyFormatter(separator, symbol, symbolFirst, value) {
- let result = Math.trunc(value) + separator;
- result += value.toFixed(2).substr(-2,2);
- if (symbolFirst){
- return symbol + ' ' + result;
- }
- else{
- return result + ' ' + symbol;
- }
- }
- function result(formatter){
- return function (value){
- return formatter(",","$",true,value)
- }
- }
- let dollarFormatter = result(currencyFormatter);
- console.log(dollarFormatter(5345)); // $ 5345,00
- console.log(dollarFormatter(3.1429)); // $ 3,14
- console.log(dollarFormatter(2.709)); // $ 2,71
Advertisement
Add Comment
Please, Sign In to add comment