Created
April 26, 2016 07:58
-
-
Save lackneets/52ce4040493375da638fbb381ed1c3ce to your computer and use it in GitHub Desktop.
Frontend currency format solution
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> | |
<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