How can I correctly format currency using jquery?
I do not need a mask, but I need something that will format currency(in all browsers) and not allow for any letters or special char's to be typed. Thanks for the help
Example:
Valid: $50.00
$1,000.53
Not Valid: $w45.00
$34.3r6
Solution 1:
Another option (If you are using ASP.Net razor view) is, On your view you can do
<div>@String.Format("{0:C}", Model.total)</div>
This would format it correctly. note (item.total is double/decimal)
if in jQuery you can also use Regex
$(".totalSum").text('$' + parseFloat(total, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString());
Solution 2:
JQUERY FORMATCURRENCY PLUGIN
http://code.google.com/p/jquery-formatcurrency/