We help IT Professionals succeed at work.

Javascript replace function

claracruz asked
Medium Priority
Last Modified: 2012-06-27
Hello experts,

I am trying to get the current value of a textbox, add a new value to the original and assign the new total to the textbox. But unfortunately, in my textbox the original value is in the following form;


So javascript is reading it as a string. Is there anyway I can strp the pound sign or force javascript to read it as a number

Watch Question

Top Expert 2004
function poundsAsInt( textAmount )
    // Strip the "£" if it exists
    if( textAmount.charAt( 0 ) == '£' ) textAmount = textAmount.substring( 1 ) ;

    // return the number:
    return textAmount * 1.0 ;

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.