vijay Posted November 8, 2005 Share Posted November 8, 2005 Hi,FormatNumber in JavaScript Any Thing?e.g.if I have 12.3675 then I need 12.37 in javascript I made it in javascript with my own function After converting it into string and some operationBut is there any inbuilt functions which provide this functionality directly?Thanx in advanceVijay Link to comment Share on other sites More sharing options...
hacknsack Posted November 8, 2005 Share Posted November 8, 2005 In JavaScript there is the built-in "toFixed()" that will provide a formatted decimal number.http://www.javascriptkit.com/javatutors/formatnumber.shtmlYou'll want to use parsefloat if the input is derived from a "text" input. <script type="text/javascript">function mkFixed(form){alert(parseFloat(form.elements['t1'].value).toFixed(2));return false;}</script></head><body><form onsubmit="return mkFixed(this)">Your Float: <input type="text" name="t1"><p><input type="submit" value="Format Number"></p></form> Thanks, Link to comment Share on other sites More sharing options...
vijay Posted November 9, 2005 Author Share Posted November 9, 2005 Hi,hacknsackThanx Vijay Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now