Jump to content

Like FormatNumber in JavaScript Any Thing?


vijay

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...