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?
Alternatively, you can use the str. split() method. To get the substring after a specific character: Use the split() method to split the string on the character.
JavaScript provides three functions for performing various types of string trimming. The first, trimLeft() , strips characters from the beginning of the string. The second, trimRight() , removes characters from the end of the string. The final function, trim() , removes characters from both ends.
You can use the substring function:
let str = "12345.00"; str = str.substring(0, str.length - 1); console.log(str);
This is the accepted answer, but as per the conversations below, the slice syntax is much clearer:
let str = "12345.00"; str = str.slice(0, -1); console.log(str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With