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 post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...