# Temperature conversion command

Hi,

I am super new to trying to create my own commands and using API’s etc.

I have done a search and only been able to find things relating to the weather command which isn’t what I want. I am trying to create a way to do temperature conversion from ºC to ºF and vice versa in 2 commands based on the number it’s given but everything I’ve tried is just giving an error, does anyone have any advice or help for how to make it work?

Many thanks

i made one that goes both ways at the same time, u just type a number, like “`!tempcalc 20`” and it replies with “`20ºC = 68ºF and 20ºF = -6.667ºC`” like this…

``````\$(eval let i=`\$(query)`,x=i*1;i==x?`\${x}ºC = \${32+(x*9/5)}ºF and \${x}ºF = \${(x-32)*5/9}ºC`:`Numbers only please`)
``````

and for 2 separate commands like u asked…
for ºF to ºC…

``````\$(eval let i=`\$(query)`,x=i*1;i==x?`\${x}ºF = \${(x-32)*5/9}ºC`:`Numbers only please`)
``````

and for ºC to ºF…

``\$(eval let i=`\$(query)`,x=i*1;i==x?`\${x}ºC = \${32+(x*9/5)}ºF`:`Numbers only please`)``
1 Like

Oh this was perfect! Thank you so much!

1 Like

no problemo… i just made it do the math straight up, i could make it round so it doesn’t give really long decimals if u wish ^^

Oh that would be great actually! Thank you. Maths isnt my strong suit at the best of times so incorporating maths inside of the command too was just leading me in circles i couldn’t get out of!

1 Like

XD
not sure which u picked, so i’ll do it for all 3…
both at once

``````\$(eval let i=`\$(query)`,x=i*1;i==x?`\${x}ºC = \${Math.round((32+(x*9/5))*1000)/1000}ºF and \${x}ºF = \${Math.round(((x-32)*5/9)*1000)/1000}ºC`:`Numbers only please`)
``````

ºF to ºC…

``````\$(eval let i=`\$(query)`,x=i*1;i==x?`\${x}ºF = \${Math.round(((x-32)*5/9)*1000)/1000}ºC`:`Numbers only please`)
``````

ºC to ºF…

``````\$(eval let i=`\$(query)`,x=i*1;i==x?`\${x}ºC = \${Math.round((32+(x*9/5))*1000)/1000}ºF`:`Numbers only please`)
``````

i did it to the 3rd decimal, most do it to the 2nd decimal, but personally i like a little more accuracy on the ºC side… but if u wanna change it, just add more zeros to each of the “1000”'s to have more decimals or remove zeros for less decimals…
p.s. just make sure where it has `*1000)/1000` those numbers r the same… like `*100)/100` for 2 decimals and so on

1 Like