How to resolve the algorithm Currency step by step in the Maple programming language
How to resolve the algorithm Currency step by step in the Maple programming language
Table of Contents
Problem Statement
Show how to represent currency in a simple example, using a data type that represent exact values of dollars and cents.
The IEEE 754 binary floating point representations of numbers like 2.86 and .0765 are not exact. For this example, data will be two items with prices in dollars and cents, a quantity for each, and a tax rate. Use the values:
(That number of hamburgers is a 4 with 15 zeros after it. The number is contrived to exclude naïve task solutions using 64 bit floating point types.)
Compute and output (show results on this page):
The tax value must be computed by rounding to the nearest whole cent and this exact value must be added to the total price before tax.
The output must show dollars and cents with a decimal point.
The three results displayed should be:
Dollar signs and thousands separators are optional.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Currency step by step in the Maple programming language
Source code in the maple programming language
Digits := 50;
tax := .0765;
burgersquantity := 4000000000000000;
burgersprice := 5.50;
burgerscost := burgersquantity * burgersprice;
milkshakesquantity := 2;
milkshakesprice := 2.86;
milkshakescost := milkshakesquantity * milkshakesprice;
total := burgerscost + milkshakescost;
printf("%.2f\n",total);
totaltax := total * tax;
printf("%.2f\n",totaltax);
totalprice := totaltax + total;
printf("%.2f\n",totalprice);
You may also check:How to resolve the algorithm Character codes step by step in the Racket programming language
You may also check:How to resolve the algorithm Modular inverse step by step in the Comal programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the C# programming language
You may also check:How to resolve the algorithm Averages/Simple moving average step by step in the Lua programming language
You may also check:How to resolve the algorithm Abstract type step by step in the Elena programming language