Twine Q&A - Recent questions tagged 1x
http://twinery.org/questions/tag/1x
Powered by Question2AnswerMy Percentage Amalgamation system calculates certain number values incorrectly
http://twinery.org/questions/1754/percentage-amalgamation-calculates-certain-incorrectly
<p>Greetings,</p><p>I've made a system that calculates percentages;</p><pre><code><<set $RandomValuePreliminary to 0.29>>
<<set $RandomValueActual to $RandomValuePreliminary * 100>></code></pre><p>The problem therein, is that $RandomValueActual is not simply the value "29", but is in fact " 28.999999999999996 ", which does not coincide with what my calculator says, nor do I think it possible in the first place (I know my math is bad, but I don't think it could be so bad as to return this number). I've tried to rectify the problem with this;</p><pre><code><<set $RandomValueActual to Math.trunc($RandomValueActual)>></code></pre><p>But this actually does not round the value up to the nearest whole number, instead it seems to round it down, in this case back down to 28. This does not happen with every number however, only specific numbers including this one, and seemingly other odd numbers like this one. I'm completely stumped as to an explanation here. Anyone else have anything? I have absolutely no idea. I'd appreciate any help anyone can offer on the subject. Thank you.</p>http://twinery.org/questions/1754/percentage-amalgamation-calculates-certain-incorrectlyFri, 29 Sep 2017 21:18:02 +0000