Further examples:

quantity = 20.5
unit_cost = Decimal('2.99')

total_cost = Decimal(str(quantity)) * unit_cost

Or using the the example you provided above:

if ((form.vars.drops * form.vars.price_change) / form.vars.start_price) < 
0.20

Assuming that form.vars.drops is a float, and form.vars.price_change and 
form.vars.start_price are both Decimals:

if ((Decimal(str(form.vars.drops)) * form.vars.price_change) / 
form.vars.start_price) < Decimal('0.20')

Mixing floats and Decimals is frustrating, so I always try to make anything 
(like a quantity field) that requires math with price fields a decimal as 
well:

db.define_table('order',
    Field('order_number', length=10),
    Field('quantity', 'decimal(10,2)'),
    Field('unit_price', 'decimal(10,2)')
)

Then a calculation like this is easy:
total_price = order.quantity * order.unit_price

Reply via email to