# That old chesnut - money. And decimal numbers [I7]

I’m sorry for bringing this one up again, but I’m not really getting on with the documentation about “money”. And also run into the thing where Inform7 rounds to the nearest whole number.

I’d like to implement a fairly simply £x.xx Pounds/Pence (dollar/cents etc.) cost system for the player to buy supplies, but something that costs £2.50 is merely costing 2.

There are several extensions in the list [on the Inform website] of various ages - would someone be kind enough enough to point me in the direction of a simple one, that works with 6M62?

Thanks

Have you looked at the chapter on money in the Recipe Book? (Sorry if that’s what you meant, many people forget about the recipe book.)

inform7.com/learn/man/RB_9_4.html

It discusses decimal money, bargaining, and implementing coins with values as well.

Are you specifying it with a decimal point where you define the kind? The “Widget Enterprises” example in the Recipe Book page that HanonO linked has:

``A monetary value is a kind of value. \$1.99 specifies a monetary value with parts dollars and cents. ``

And at the end of 15.8 in the Inform manual it says that numeric kinds default to whole-number values but that if you include a decimal point in the unit specification you will get real numbers instead.

Just as a general programming suggestion not specifically related with Inform: Perhaps it can help to work with cents as unit, so you will have 250 cents, not 2.50 pounds/dollars. When you print them on screen you can convert them easily to full unit dividing the amount by 100.

That way you will avoid working with floating point arithmetic, at least if your operations are simply additions and subtractions.

As an evidence of the problem with that, you can open the console in your Google Chrome browser, for example, using CTRL + SHIFT + J and then write 1.1 + 1.3 to get an amazing result of 2.4000000000000004

X.X

If you sum 110 + 130 and then divide by 100 you will get a fantastic 2.4

Hi,

I did try representing as whole numbers and dividing on print, but Inform said “no” and rounded to integers

I’m not an Inform guy so let’s see what experts say. Meanwhile, you could check if you are using “Number” instead of “Real Number”, as stated in this document:

§15.2. Numbers and real numbers