Calculate percentage from counter

So I used this link to make a counter Adding a command that adds the amount specified to a counter and that works well. It is a kill counter for Valo, I altered it a bit so it says ‘The counter value is (value) of targetvalue’ but I also want a percentage behind it so you can see more clearly how close we are to getting the goal.

Anyone that can help out?

Hey @Sinful_Reaper3!

Before that sentence

`The counter value is ${a.reduce((b,c)=>b+parseInt(c)||b)}`

add the following code and edit the response like so:

t=YOUR_TARGET_VALUE; c=a.reduce((x,y)=>x+parseInt(y)||x); p=Math.round((c*100/t)*100)/100; `The counter value is ${c}, or ${p}%`

Replace YOUR_TARGET_VALUE with the number you’re targeting, don’t put any type of quotes, just the number.

Hey Emily,

Thanks for answering, I can’t seem to do it right tho

This is the code I used before
$(eval a=$(urlfetch json https://twitch.center/customapi/quote/list?token=?????&no_id=1).split(~);a.unshift(0);The counter value is ${a.reduce((b,c)=>b+parseInt(c)||b)}/30.069 kills. Next Milestone = 15.000 kills)

This is the code after your reply
$(eval a=$(urlfetch json https://twitch.center/customapi/quote/list?token=?????&no_id=1).split(~);a.unshift(0);The counter value is ${a.reduce((b,c)=>b+parseInt(c)||b) t=30069; c=a.reduce((x,y)=>x+parseInt(y)||x); p=c*100/t;} (${p}%) Next Milestone = 15.000 kills)

Hope you can see where I made the mistake.
Thanks for the help

You simply didn’t put the code where I said, here’s the fix:

$(eval a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`.split(`~`); a.unshift(0); t=30069; c=a.reduce((x,y)=>x+parseInt(y)||x); p=Math.round((c*100/t)*100)/100; `The counter value is ${c} (${p}%) | Next milestone = 15.000 kills`)

I also took the opportunity to refine the percentage, so it only goes up to 10^-2 of precision, instead of possibly 10^-14, it’ll look cleaner.

Oh I thought you meant add the code, but it was replacing :sweat_smile:.
Thanks for the help Emily!
Have a good day

1 Like

No problem, I could have been clearer from the start.
Have a good day!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.