# Squaring quantities with units

I am programming a script to an online store and a serious mathematical problem happened, and I cannot solve it!

This is the problem: if a person has only 10 cents (on any monetary currency, I will use US Dollar for example) it's the same as say that this person has $0.1 right? I mean 10 cents =$ 0.1 , right?

Now, lets square it. The 10 cents becomes 100 cents, which is 1 dolar. Right? But 0.1*0.1 = $0.01. I am very sure I can do this math using cents OR using any other unit I want and the result should be the same. If I have the same example and I want to make the square with a number that is in meters and other is in kilometer. The result should be the same, but it is not! What is the issue here? EDIT: One final question, a function with$x^3$should increase faster than$x^2$right? For example,$2^2 = 4$and$2^3 = 810^2 = 100$and$10^3 = 100$So the$x^3$graphic should always be on top of$x^2$. Why doesnt that happen all the time? OBS: this edit looks not related to my main question but it is completely, depending on the answer. • The units change when you square things - one square dollar = 10,000 square cents - just like one square metre = 10,000 square centimetres – Mark Bennet May 21 '15 at 16:54 • An interest rate, in the form$1+r$where$100r$is the percentage rate, is a dimensionless ratio between the sum of money at the end and the sum at the beginning – Mark Bennet May 21 '15 at 16:57 • taking mental note of carefully checking the units before shopping at sitepor500.com.br – mickep May 21 '15 at 17:01 • So this is what happened in 2008. – Calum Gilhooley May 21 '15 at 17:40 • If there are units of currency occurring anywhere in your interest rates, you're doing it wrong. Plainly and simply wrong. Go back and correct whatever mistaken idea caused the$\$^{-1}$ to sneak into your interest rate, correct or re-do everything that was affected by that mistaken idea, and be careful not to make that mistake again. – David K May 21 '15 at 18:39

The problem is you aren't keeping track of the units properly. $(10\textrm{ cents})^2=100\textrm{ cents}^2$ whereas $(\$0.1)^2=\$^20.01$. Note that since $100\textrm{ cents}=\$1$, we have that$10000\textrm{ cents}^2=\$^21$. Using this unit conversion, the equality that looked weird to you holds.

• AMAZING!!! I SPENT MANY DAYS INTO THIS!!! Thank you A LOT! I will save the squared unit in my database and make sure when I change to another unit I make the correct conversion! – Sitepor500.com.br May 21 '15 at 16:57
• @Sitepor500.com.br Glad to be helpful :) – jgon May 21 '15 at 16:58
• @Sitepor500.com.br consider accepting this answer to let other users know that this is the right one. – SalmonKiller May 21 '15 at 16:58
• @SalmonKiller Not necessarily that it is the right one per se but the most helpful ;) – Daniel W. Farlow May 21 '15 at 16:59
• I am trying to accept this answer but SE says I need to wait more 6 minutes. I will do that :) I am very glad to you. – Sitepor500.com.br May 21 '15 at 17:00

The calculation is correct (though you have named the units incorrectly).

I doubt you have a problem with the fact that 1 yard = 3 feet, but 1 square yard = 9 square feet. It's the same sort of thing.

• You are right, I edited the question can you help me answer the bottom of it? – Sitepor500.com.br May 21 '15 at 17:03
• It's unrelated. You should pose it as another question. Piggybacking questions is frowned upon. Post another and I will read it. – MPW May 21 '15 at 21:48

If you square 10 cents, then you have 100 "square-cents". If you square 0.1 Dollar, then you have 0.01 "square-Dollars". Now, 100 "square-cents" is the same as 0.01 "square-Dollars".

Maybe it's not such a good idea to square money...

• squaring money is needed in my case cause I need it to calculate intererest rate of a purchase that is made in several months. I use a strange formula from my customers that squares everything including the money, not only the interest rate. – Sitepor500.com.br May 21 '15 at 16:59
• It is a good idea to never pass around raw numbers or strings in code for this reason. It's the main reason why constructors exist: d := Dollar(0.1); c := Cents(d.toCents()). – Rob May 21 '15 at 18:17

If you have \$0.10 and you want to collect ten of them, then the calculation is simple: "10 x \$0.10 = \$1", which is what you expect. Conversely, when you say you want to "square" ten cents, what you're really saying is you want to "ten cents the ten cents", which doesn't make any sense. Alternatively, if you view each cent as one percent (which is where the term "percent" came from, "per cent" or "per one hundred"), ten cents is thus 10%, which if squared, means "10% of 10%", which is 1%. • I never heard that analogy that percent is "per cent". Really nice man. Great explanation – Sitepor500.com.br May 22 '15 at 0:13 You probably don't want to square the money (otherwise, the unit would change from cents or$\ to cents^2 or $\$^2$, and the result you get in these units is not a contradiction); more likely, you expect a result tantamount to multiplying the amount by 10. • But I need to use interest rate that was converted from % to$ that's why I need to square it. Can you also help me answer the bottom of my question? – Sitepor500.com.br May 21 '15 at 17:04
• % is a ratio without units (call it the unit 1). 90% could come from: (9 dollars)/(10 dollars) = 0.9 = 90%. If you want a percentage of an original amount: \$600 * 90%, which is in dollars. ((\$600 * 90%) * 90% )* 90%) = \$600 * (90% * 90% * 90%) is in dollars as well. Notice that the rate keeps getting exponentiated, not the dollars. – Rob May 21 '15 at 18:32 • For you last question:$x^3 > x^2$when$x > 1$; the behavior is opposite for$0 \leq x <1\$. – Clement C. May 21 '15 at 18:37