Jump to content

Outputting as currency


bradley.lee

Recommended Posts

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

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...