JavaScript chop/slice/trim off last character in string

I have a string, 12345.00, and I would like it to return 12345.0.

I have looked at trim, but it looks like it is only trimming whitespace and slice which I don't see how this would work. Any suggestions?

Text Copied From stackoverflow.com
on : Thu, Jun 04, 2009 Views : 1147201

Accepted Answer

You can use the substring function:

var str = 12345.00;
 str = str.substring(0, str.length - 1);
 
// 12345.0 

This is the accepted answer, but as per the conversations below, the slice syntax is much clearer:

var str = 12345.00;
 str = str.slice(0, -1);
 
// 12345.0 
Text Copied From stackoverflow.com
on : Thu, Jun 04, 2009

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp