Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

How to display variables with consistent decimal places and also do math on them?

$
0
0
I've got a game with a wallet that keeps track of how much money the player has, and players can buy things in increments of 25 cents. However, I can't get the wallet to consistently display to two decimal places, so when the player has $1.50 it displays as $1.5.

I've tried using .toFixed(2):
(set: $money to (it-1.75).toFixed(2))

but then when the player tries to buy things they get an "undefined" error and the wall. It seems that these variables are being interpreted as strings instead of numbers, and that's why the math isn't working, so I tried using Number:
(set: $money to Number((it-1.75).toFixed(2)))

This does the math, but then it goes back to dropping the zeros on numbers like 1.50 (so I'm back to my original problem).

I'm working in Harlowe, and most of the discussion on decimal points seems to be in Sugarcube. Any folks working with decimal places in Harlowe have any advice?

Viewing all articles
Browse latest Browse all 1844

Trending Articles