Skip to content


Javascript – Currency Format

/* formater */
function digit_grouping(nStr) {

	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
/*currency format */
function currencyFormat(variable) {
	var new_value = variable.value.replace(/\,/g, "");
	variable.style.textAlign = "right";
	variable.value = digit_grouping(new_value);
}
<input name="product_value" id="product_value" type="text" size="20" onkeyup="currencyFormat(this);" />

Sumber : http://scentsofme.com/currency-format-using-javascript/

Posted in IT's tips and tricks.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.