Javascript simple math error -


I do not understand what this is, though math is never my specialty, so any help would be appreciated. Is performed. My simple equation is in two parts: Answer 1) 226 - [value] multiplied by 9.

Answer 2) 226 - By multiplying [value] .55

If you use 40 as the input value, then my calculator says: < P> Answer 1) 226 - 40 = 186 * .9 = 167.4

Answer 2) 226 - 40 = 186 * .55 = 102.3 < / P>

But my code says:

Answer 1) 190

Answer 2) 204

My code:

  HTML: & lt; Input id = "hr" size = "4" value = "" /> gt; & Lt; Span id = "number" & gt; & Lt; / Span & gt; Answer 1 & lt; Strong & gt; & Lt; Span id = "answer1" & gt; & Lt; / Span & gt; & Lt; / Strong & gt; & Lt; Br> Answer 2 & lt; Strong & gt; & Lt; Span id = "answer2" & gt; & Lt; / Span & gt; & Lt; / Strong & gt; & Lt; / P & gt; & Lt; A href = "#" square = 'THR' & gt; Click to compute & lt; / A & gt; Script: & lt; Script type = "text / javascript" & gt; $ ('A.THR'). Click (function () {var value = parseInt ($ ("#HR") .val ()); $ ("# answer1") .html (226 - value * 0.9); $ ("# answer2"). Html (226 - value * 0.55); return back;}); & Lt; / Script & gt;    

You are forgetting the operation order. Mostly predecessor compared to multiplication / addition. Place brackets around your 226-value

  $ ("# answer1") .html ((226-value) * 0.9); $ ("# Answer2"). HTML ((226 - value) * 0.55);   

Reading your question again, I do not know what exactly is your desired outcome. If you want to multiply first and then subtraction, then you do not need brackets, though it To clarify, 226 - (value * 0.9) can be helpful in writing. What is happening on your calculator, though it is that you are typing 226 - value and after you increase the result of your decimal number then the above code, (226 - value) * 0.9 < / Code> indicates your typing, can help to say that what you are trying to do with interval user perspective, to determine where your brackets are.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -