types

decimal

Exact, money-safe decimal numbers and the methods available on them.

A decimal is an exact decimal number, safe for money where a float would lose precision. As a schema field it is written amount: decimal. A request can send it as a number or a string ("19.90"), and it is coerced without rounding error.

marreta
total = order.amount
cents = total.round(2)

Methods

NameSignatureSummary
decimal.roundround(places)Rounds using banker’s rounding.
decimal.ceilceil()Rounds up.
decimal.floorfloor()Rounds down.
decimal.trunctrunc()Truncates toward zero.
decimal.absabs()Returns the absolute value.
decimal.scalescale()Returns the number of decimal places.
decimal.to_integerto_integer()Converts to an integer, truncating toward zero.
decimal.to_floatto_float()Converts to a float.
decimal.to_stringto_string()Converts to a string.