We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi! I work with Processing sinds 2 months for a school project. Now I have a calculation problem. This is the code:
output.println (round((abs((lul)-(lengthCompareLine[i])))*100/(lengthCompareLine[i])));
lengthCompareLine is an array with random length of lines, and lul is a user line which can be adjusted by the user. Now I want to compare these 2 lines to get a % value of the difference. Unfortunatly the code seems to work properly if the user line (lul) is shorter, but not if its longer. Than it gives out values of f.ex. 320 %, which cant be right. Can I calculate the difference of the lines independent from which line is longer.
Thanks for your help! numan21
Answers
are these integers?
i think you have integer division problems...
http://wiki.processing.org/w/Troubleshooting#Why_does_2_.2F_5_.3D_0_instead_of_0.4.3F
thanks for your fast reply! no they are all floats. i just want to round the result in the end so that it it doesn´t print out a number like this 34.872526271 %. I think the problem is that the formule i use is not correct because the compareline can be longer than the lul. maybe thats the problem. but than i need another formule?! or is it possible to calculate it in any other way?
so give us some examples replacing lul and lengthCompareLine, tell us what you get and what you'd expect. we have no idea of the range of input...
nf() will allow you to format output - http://processing.org/reference/nf_.html