Skip to content

Instantly share code, notes, and snippets.

@carlesandres
Created May 18, 2015 15:35
Show Gist options
  • Save carlesandres/d0ec36edffe2c8801f6c to your computer and use it in GitHub Desktop.
Save carlesandres/d0ec36edffe2c8801f6c to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/vogonehayo
<!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>
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