Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This we did in one of our project long back. I just find out the code . Our application was in asp.net. Function <strong>dollarAmount</strong> does the work</p> <pre><code>function checkNum(data) { // checks if all characters var valid = "0123456789."; // are valid numbers or a "." var ok = 1; var checktemp; for (var i=0; i&lt;data.length; i++) { checktemp = "" + data.substring(i, i+1); if (valid.indexOf(checktemp) == "-1") return 0; } return 1; } function dollarAmount(form, field, appendZero) { Num = "" + eval("document." + form + "." + field + ".value"); if(Num=="") { eval("document." + form + "." + field + ".value = '" + 0 + "';"); return; } dec = Num.indexOf("."); end = ((dec &gt; -1) ? "" + Num.substring(dec,Num.length) : ""); Num = "" + parseInt(Num); var temp1 = ""; var temp2 = ""; //var appendZero=1; if (checkNum(Num) == 0) { //alert("This does not appear to be a valid number. Please try again."); } else { if(appendZero==1 || end !="") { if (end.length == 2) end += "0"; if (end.length == 1) end += "00"; if (end == "") end += ".00"; } var count = 0; for (var k = Num.length-1; k &gt;= 0; k--) { var oneChar = Num.charAt(k); if (count == 3) { temp1 += ","; temp1 += oneChar; count = 1; continue; } else { temp1 += oneChar; count ++; } } for (var k = temp1.length-1; k &gt;= 0; k--) { var oneChar = temp1.charAt(k); temp2 += oneChar; } temp2 = temp2 + end; eval("document." + form + "." + field + ".value = '" + temp2 + "';"); } } </code></pre> <p>We called this function like this</p> <pre><code>txtBox.Attributes.Add("OnBlur", "return DollarAmount('" + txtBox.ID + "',0)"); </code></pre> <p>Also after googling I found this links</p> <p>a) <a href="http://www.web-source.net/web_development/currency_formatting.htm" rel="nofollow noreferrer">Use JavaScript to Format Currency within Your Web Page</a></p> <p>b) <a href="http://javascript.internet.com/forms/currency-format.html" rel="nofollow noreferrer">Currency Format</a></p> <p>Also I guess that JQuery may have some plugin for serving the purpose <a href="http://plugins.jquery.com/node/3796" rel="nofollow noreferrer">Currency: an unobstrusive automatic and real time currency conversion</a></p> <p>But I doubt if any inbuilt function is available in javascript. Please let me know if you found any. I would love to know.</p> <p>Thanks .</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload