bradley.lee Posted October 11, 2005 Share Posted October 11, 2005 Is there any way for an answer to be output so that it would appear as a currency (£) in particular or at least rounding to 2 decimal places. You can round up to pounds but not to any other point Link to comment Share on other sites More sharing options...
aaronjones3593 Posted October 16, 2005 Share Posted October 16, 2005 Hmm, you got me stuck there.Try this: var something = "64.83657639"; // Number you want to format, must be in quotesvar decimalPos = something.indexOf(".");var otherthing = something.substring(0,decimalPos + 3);var decimalPlc = parseInt(something.charAt(decimalPos + 3));if (decimalPlc > 5){ otherthing = parseFloat(something.substring(0,decimalPos + 3)) + 0.01;}var finalOutpt = "£ " + otherthing; EDITED FOR SUPPORT OF NUMBERS GREATER THAN 9.99Where finalOutpt would be the variable containing the formatted version of the number.The number you want to format must be enclosed in quotes (Must be treated as string) otherwise you would get a object does not support this method error.Hope that helps, I did test it and it does work, but don't know whether it was what you were looking for. 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