javascript - Dealing with Negative Numbers in Strings -


I have a simple but troubled problem with the monastery.

The following code will take a number from the string (usually contained in the SPAN or DIV) and decrease the value of 1 from it.

.replace (/ (\ d +) / g, function (a, n) {return (+ N-1);});

This really works well, except that when we get less than zero, once we go for -1, then we can clearly define negative subtraction Working together.

-1 - 1 = -0, -0 - 1 = - 1

How can I avoid it? It seems like I have a common problem with mathematics here.

The problem is that your function "-1" is not treated as negative - it is positive 1 After being considered as hyphen.

/ (-? \ D +) / g will capture a key hyphen okay.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -