[removed] calculate x% of a number

后端 未结 10 1842
-上瘾入骨i
-上瘾入骨i 2020-12-12 15:07

I am wondering how in javascript if i was given a number (say 10000) and then was given a percentage (say 35.8%)

how would I work out how much that is (eg 3580)

10条回答
  •  无人及你
    2020-12-12 15:12

    Best thing is to memorize balance equation in natural way.

    Amount / Whole = Percentage / 100
    

    usually You have one variable missing, in this case it is Amount

    Amount / 10000 = 35.8 / 100
    

    then you have high school math (proportion) to multiple outer from both sides and inner from both sides.

    Amount * 100 = 358 000
    
    Amount = 3580
    

    It works the same in all languages and on paper. JavaScript is no exception.

提交回复
热议问题