Skip to content

Instantly share code, notes, and snippets.

@lackneets
Created April 26, 2016 07:58
Show Gist options
  • Save lackneets/52ce4040493375da638fbb381ed1c3ce to your computer and use it in GitHub Desktop.
Save lackneets/52ce4040493375da638fbb381ed1c3ce to your computer and use it in GitHub Desktop.
Frontend currency format solution
<!DOCTYPE html>
<html>
<head>
<title>Example of Currency</title>
<!-- Javascripts here -->
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script>
$(function(){
$('.currency').each(function(){
$(this).text(function(i, text){
return String(text).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
});
});
});
</script>
<style>
.currency{
vertical-align: middle;
color: #f2172b;
margin: 0 0.2em;
}
.currency:before{
content: "$";
font-size: 0.8em;
margin-right: 0.2em;
}
</style>
</head>
<body>
This example now only <span class="currency">7990</span>!!
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment