Java script for changing categories into percentages

Comments

3 comments

  • Charl Henning

    Hello Will
    I have a similar problem and was wondering if you found a solution to the percentage calculation issue? If so and if you are willing to share that with me I would greatly appreciate it.

    0
    Comment actions Permalink
  • Yohan Hidalgo

    Having the same issue here..

    a = 200
    b = 25%

    Math.ceil((a*b)/25,0)*25

    How can I multiply a times b, when b is a percentage integer. what should I multiply by instead of 25%?

    Thanks!

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Yohan,

    is b the "content" of a category option (= a string)? E.g. if you have a category field with options like 10%, 20%, 25%, 30%.
    And do you want a) to multiply 200 * 25 = 5000, or b) to get 25% of 200 = 50?

    If b is a string, you can do for a):
    a = 200
    b = @category field
    c= parseInt(b.replace(/%/,""),10)
    Math.ceil((a*c),0)

    for b):
    Math.ceil(a*c/100)

    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk