liveBook · Manning

Monetary amount

A monetary amount is a quantity of money represented by a numeric value together with a currency.

How 2 Manning books explain it

Learn Go with Pocket-Sized Projects

An amount is a monetary value whose numeric representation is interpreted with a currency and subject to supported precision constraints.

How it is used
Represents the quantity-and-currency input and output of a command-line currency converter.
How deep it goes
Works through representation, construction, conversion, validation, and tests, while retaining explicit supported-range limitations.
Examples
Uses 19.8875 Canadian dollars as an invalid amount and conversion tests covering target precision, large values, and small rates.
What you can do after
Build it from scratch as a validated Go Amount type and test its construction and conversion boundaries.

Read how Learn Go with Pocket-Sized Projects explains monetary amount →

Building User-Friendly DSLs

A DSL type whose values represent monetary amounts.

How it is used
Enables rental-price attributes and expressions to represent dollar values distinctly from percentages and date ranges.
How deep it goes
Works through bottom-up expression typing on ASTs, including references, binary operations, parentheses, and an untyped fallback.
Examples
Uses a discounted rental-price expression with amount references, a percentage discount, of, and subtraction.
What you can do after
Evaluate/understand whether rental-price expressions compute to an amount and why invalid type combinations require errors.

Read how Building User-Friendly DSLs explains monetary amount →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.