Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Precision follows <a href="http://en.wikipedia.org/wiki/Significant_figures" rel="nofollow">sig figs</a>, not fractional digits. you should remove the <code>getcontext().prec = 2</code> and change the last line to:</p> <pre><code>print 'the result of the currency conversion was ', currencyAmount.quantize(Decimal('0.00')) </code></pre> <p><strong>EDIT</strong></p> <p>i've tried this code below and it works correctly:</p> <pre><code>#setup the decimal data type (including number of decimal places) import decimal #get the current value and type from the user currencyAmount = decimal.Decimal(raw_input('please enter the amount: ')) currencyType = int(raw_input('please enter the type (1 = pound, 2 = euro, 3 = dollar, 4 = yen): ')) #set the exchange rates (based on sterling) euro = decimal.Decimal('1.5') dollar = decimal.Decimal('2.7') yen = decimal.Decimal('30.8') #convert the currency into pound sterling if (currencyType == 2): currencyAmount = currencyAmount / euro elif (currencyType == 3): currencyAmount = currencyAmount / dollar elif (currencyType == 4): currencyAmount = currencyAmount / yen #ask the user what currency they want it converted into currencyConvert = int(raw_input('please enter the currency you would like to convert to (1 = pound, 2 = euro, 3 = dollar, 4 = yen): ')) #convert the currency into the new format (pound already done in previous steps) if (currencyConvert == 2): currencyAmount = currencyAmount * euro elif (currencyConvert == 3): currencyAmount = currencyAmount * dollar elif (currencyConvert == 4): currencyAmount = currencyAmount * yen #display the result to the user print 'the result of the currency conversion was ', currencyAmount.quantize(decimal.Decimal('0.00')) </code></pre> <p>output:</p> <pre><code>please enter the amount: 100 please enter the type (1 = pound, 2 = euro, 3 = dollar, 4 = yen): 2 please enter the currency you would like to convert to (1 = pound, 2 = euro, 3 = dollar, 4 = yen): 4 the result of the currency conversion was 2053.33 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload