If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.4.0
Story Format: Harlowe 3.3.0
I was trying to do some (hopefully very simple) maths in my story, but I clearly don’t understand even simple maths, because it’s gone terribly skew-whiff.
I wanted to assign a variable ($vol1) to any of a set of possible numbers and then multiply that number by 23. (Simple, right?)
I set up my code like this:
(set: $vol1 to (either: 0.1, 0.25, 0.50, 0.75, 1.1, 1.5, 2.0))
(set: $a1 to (23 * $vol1))
(set: $a2 to (string: $a1))
(print: $vol1) - this is the vol value that was selected <br>
(print: $a1) - this is variable a1 <br>
(print: $a2) - should be a string of a1
and then tested it out. It works correctly most of the time (by which, I mean that it multiplies $vol1 by 23, and spits that out as $a1 and $a2 (just double-checking, lol).
(For example:
0.25 - this is the vol value that was selected
5.75 - this is variable a1
5.75 - should be a string of a1
and that is what I expected it to print.)
This code doesn’t, however, work correctly when $vol1 is chosen as 0.1. It outputs this instead:
0.1 - this is the vol value that was selected
2.3000000000000003 - this is variable a1
2.3000000000000003 - should be a string of a1
…and then at this point I started questioning my sanity (and understanding of maths), because why is $a1 not 2.3?
If I remove 0.1 from the possible options for $vol1, all of the other numbers still work as previously, so I guess it must be something special about 0.1 as a number (and not its position in the list of options?)
I guess it isn’t a huge deal in the scope of things (I can take out 0.1 from the list without any problems) - but what did I do wrong, and what is different about 0.1? Are there other numbers I should avoid because they’ll return the same problem?
Thanks in advance for any help - I know it’s an incredibly stupid question, probably I should really be sent back to a basic maths class but I can’t seem to figure this out on my own!