Created
May 18, 2015 15:35
-
-
Save carlesandres/d0ec36edffe2c8801f6c to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/vogonehayo
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function currencyFormat(n, lang) { | |
var opts = {}; | |
opts.style = "currency"; | |
opts.currency = "USD"; | |
if(window.Intl) { | |
var formatter = new window.Intl.NumberFormat(lang,opts); | |
return formatter.format(n); | |
} else { | |
return n; | |
} | |
} | |
console.log(currencyFormat(123456.89,'en')); | |
console.log(currencyFormat(123456.89,'es')); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function currencyFormat(n, lang) { | |
var opts = {}; | |
opts.style = "currency"; | |
opts.currency = "USD"; | |
if(window.Intl) { | |
var formatter = new window.Intl.NumberFormat(lang,opts); | |
return formatter.format(n); | |
} else { | |
return n; | |
} | |
} | |
console.log(currencyFormat(123456.89,'en')); | |
console.log(currencyFormat(123456.89,'es')); | |
</script></body> | |
</html> |
This file contains hidden or 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
function currencyFormat(n, lang) { | |
var opts = {}; | |
opts.style = "currency"; | |
opts.currency = "USD"; | |
if(window.Intl) { | |
var formatter = new window.Intl.NumberFormat(lang,opts); | |
return formatter.format(n); | |
} else { | |
return n; | |
} | |
} | |
console.log(currencyFormat(123456.89,'en')); | |
console.log(currencyFormat(123456.89,'es')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment