# jQuery math finally solved

May 7th, 2012 by Michael JasperWeb designers have long struggled with some of the more advanced aspects of computation and mathematics. Sometime ago, a Stack Overflow question asked

I’ve got a number in my JavaScript variable! Now how do I add another number to it? Please

A few well meaning answers point to using jQuery as the obvious solution. However, after a in depth search, *I couldn’t find any actual jQuery plugins to do the calculations!*

Well, there is a new jQuery plugin in town that aims to solve the problem of arithmetic in JavaScript: jMath!

It is incredibly easy to use in your code:

1 2 3 |
<script> $("#result").math('+', 2, 5); //7 </script> |

The plugin accepts the following operators:

- ‘+’ (addition)
- ‘-‘ (subtraction)
- ‘*’ (multiplication)
- ‘/’ (division)

And looking to add more in the future.

Hope that this helps in your development. Thanks!

Pingback: The DOM isn’t slow, you are. | Wat, blogged