WeixiangYan/CodeTransOcean huggingface dataset:
Task: Currency





Java: import java.math.*;
import java.util.*;

public class Currency {
    final static String taxrate = "7.65";

    enum MenuItem {

        Hamburger("5.50"), Milkshake("2.86");

        private MenuItem(String p) {
            price = new BigDecimal(p);
        }

        public final BigDecimal price;
    }

    public static void main(String[] args) {
        Locale.setDefault(Locale.ENGLISH);

        MathContext mc = MathContext.DECIMAL128;

        Map<MenuItem, BigDecimal> order = new HashMap<>();
        order.put(MenuItem.Hamburger, new BigDecimal("4000000000000000"));
        order.put(MenuItem.Milkshake, new BigDecimal("2"));

        BigDecimal subtotal = BigDecimal.ZERO;
        for (MenuItem it : order.keySet())
            subtotal = subtotal.add(it.price.multiply(order.get(it), mc));

        BigDecimal tax = new BigDecimal(taxrate, mc);
        tax = tax.divide(new BigDecimal("100"), mc);
        tax = subtotal.multiply(tax, mc);

        System.out.printf("Subtotal: %20.2f%n", subtotal);
        System.out.printf("     Tax: %20.2f%n", tax);
        System.out.printf("   Total: %20.2f%n", subtotal.add(tax));
    }
}







Ada: with Ada.Text_IO;

procedure Currency is
   type Dollar is delta 0.01 range 0.0 .. 24_000_000_000_000_000.0;
   package Dollar_IO is new Ada.Text_IO.Fixed_IO(Dollar);

   hamburger_cost : constant := 5.50;
   milkshake_cost : constant := 2.86;
   tax_rate : constant := 0.0765;

   total_cost : constant := hamburger_cost * 4_000_000_000_000_000.0 + milkshake_cost * 2;
   total_tax : constant := total_cost * tax_rate;
   total_with_tax : constant := total_cost + total_tax;
begin
   Ada.Text_IO.Put("Price before tax:");
   Dollar_IO.Put(total_cost);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Tax:             ");
   Dollar_IO.Put(total_tax);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Total:           ");
   Dollar_IO.Put(total_with_tax);
   Ada.Text_IO.New_Line;
end Currency;
Task: Currency







Python: from decimal import Decimal as D
from collections import namedtuple

Item = namedtuple('Item', 'price, quant')

items = dict( hamburger=Item(D('5.50'), D('4000000000000000')),
              milkshake=Item(D('2.86'), D('2')) )
tax_rate = D('0.0765')

fmt = "%-10s %8s %18s %22s"
print(fmt % tuple('Item Price Quantity Extension'.upper().split()))

total_before_tax = 0
for item, (price, quant) in sorted(items.items()):
    ext = price * quant
    print(fmt % (item, price, quant, ext))
    total_before_tax += ext
print(fmt % ('', '', '', '--------------------'))
print(fmt % ('', '', 'subtotal', total_before_tax))

tax = (tax_rate * total_before_tax).quantize(D('0.00'))
print(fmt % ('', '', 'Tax', tax))

total = total_before_tax + tax
print(fmt % ('', '', '', '--------------------'))
print(fmt % ('', '', 'Total', total))





Ada: with Ada.Text_IO;

procedure Currency is
   type Dollar is delta 0.01 range 0.0 .. 24_000_000_000_000_000.0;
   package Dollar_IO is new Ada.Text_IO.Fixed_IO(Dollar);

   hamburger_cost : constant := 5.50;
   milkshake_cost : constant := 2.86;
   tax_rate : constant := 0.0765;

   total_cost : constant := hamburger_cost * 4_000_000_000_000_000.0 + milkshake_cost * 2;
   total_tax : constant := total_cost * tax_rate;
   total_with_tax : constant := total_cost + total_tax;
begin
   Ada.Text_IO.Put("Price before tax:");
   Dollar_IO.Put(total_cost);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Tax:             ");
   Dollar_IO.Put(total_tax);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Total:           ");
   Dollar_IO.Put(total_with_tax);
   Ada.Text_IO.New_Line;
end Currency;
Task: Currency








VB: Public Sub currency_task()
    
    Dim number_of_hamburgers As Variant
    number_of_hamburgers = CDec(4E+15)
    Dim price_of_hamburgers As Currency
    price_of_hamburgers = 5.5
    
    Dim number_of_milkshakes As Integer
    number_of_milkshakes = 2
    Dim price_of_milkshakes As Currency
    price_of_milkshakes = 2.86
    
    Dim tax_rate As Single
    tax_rate = 0.0765
    
    Dim total_price_before_tax As Variant
    total_price_before_tax = number_of_hamburgers * price_of_hamburgers
    total_price_before_tax = total_price_before_tax + number_of_milkshakes * price_of_milkshakes
    Debug.Print "Total price before tax "; Format(total_price_before_tax, "Currency")
    
    Dim tax As Variant
    tax = total_price_before_tax * tax_rate
    Debug.Print "Tax "; Format(tax, "Currency")
    
    Debug.Print "Total with tax "; Format(total_price_before_tax + tax, "Currency")
End Sub




Ada: with Ada.Text_IO;

procedure Currency is
   type Dollar is delta 0.01 range 0.0 .. 24_000_000_000_000_000.0;
   package Dollar_IO is new Ada.Text_IO.Fixed_IO(Dollar);

   hamburger_cost : constant := 5.50;
   milkshake_cost : constant := 2.86;
   tax_rate : constant := 0.0765;

   total_cost : constant := hamburger_cost * 4_000_000_000_000_000.0 + milkshake_cost * 2;
   total_tax : constant := total_cost * tax_rate;
   total_with_tax : constant := total_cost + total_tax;
begin
   Ada.Text_IO.Put("Price before tax:");
   Dollar_IO.Put(total_cost);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Tax:             ");
   Dollar_IO.Put(total_tax);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Total:           ");
   Dollar_IO.Put(total_with_tax);
   Ada.Text_IO.New_Line;
end Currency;
Task: Currency

C: 	mpf_set_d(burgerUnitPrice,5.50);
	mpf_set_d(milkshakePrice,2 * 2.86);
	mpf_set_d(burgerNum,4000000000000000);
	mpf_set_d(milkshakeNum,2);
Task: Currency



C#: using System;
using System.Collections.Generic;

namespace Currency
{
    class Program
    {
        static void Main(string[] args)
        {
            MenuItem hamburger = new MenuItem() { Name = "Hamburger", Price = 5.5M };
            MenuItem milkshake = new MenuItem() { Name = "Milkshake", Price = 2.86M };

            IList<CartItem> cart = new List<CartItem>();
            cart.Add(new CartItem() { item = hamburger, quantity = 4000000000000000 });
            cart.Add(new CartItem() { item = milkshake, quantity = 2 });

            decimal total = CalculateTotal(cart);

            Console.WriteLine(string.Format("Total before tax: {0:C}", total));

            
            decimal tax = total * 0.0765M;

            Console.WriteLine(string.Format("Tax: {0:C}", tax));

            total += tax;

            Console.WriteLine(string.Format("Total with tax: {0:C}", total));
        }

        private static decimal CalculateTotal(IList<CartItem> cart)
        {
            decimal total = 0M;

            foreach (CartItem item in cart)
            {
                total += item.quantity * item.item.Price;
            }

            return total;
        }

        private struct MenuItem
        {
            public string Name { get; set; }
            public decimal Price { get; set; }
        }

        private struct CartItem
        {
            public MenuItem item { get; set; }
            public decimal quantity { get; set; }
        }
    }
}
Task: Currency





Java: import java.math.*;
import java.util.*;

public class Currency {
    final static String taxrate = "7.65";

    enum MenuItem {

        Hamburger("5.50"), Milkshake("2.86");

        private MenuItem(String p) {
            price = new BigDecimal(p);
        }

        public final BigDecimal price;
    }

    public static void main(String[] args) {
        Locale.setDefault(Locale.ENGLISH);

        MathContext mc = MathContext.DECIMAL128;

        Map<MenuItem, BigDecimal> order = new HashMap<>();
        order.put(MenuItem.Hamburger, new BigDecimal("4000000000000000"));
        order.put(MenuItem.Milkshake, new BigDecimal("2"));

        BigDecimal subtotal = BigDecimal.ZERO;
        for (MenuItem it : order.keySet())
            subtotal = subtotal.add(it.price.multiply(order.get(it), mc));

        BigDecimal tax = new BigDecimal(taxrate, mc);
        tax = tax.divide(new BigDecimal("100"), mc);
        tax = subtotal.multiply(tax, mc);

        System.out.printf("Subtotal: %20.2f%n", subtotal);
        System.out.printf("     Tax: %20.2f%n", tax);
        System.out.printf("   Total: %20.2f%n", subtotal.add(tax));
    }
}
Task: Currency







Python: from decimal import Decimal as D
from collections import namedtuple

Item = namedtuple('Item', 'price, quant')

items = dict( hamburger=Item(D('5.50'), D('4000000000000000')),
              milkshake=Item(D('2.86'), D('2')) )
tax_rate = D('0.0765')

fmt = "%-10s %8s %18s %22s"
print(fmt % tuple('Item Price Quantity Extension'.upper().split()))

total_before_tax = 0
for item, (price, quant) in sorted(items.items()):
    ext = price * quant
    print(fmt % (item, price, quant, ext))
    total_before_tax += ext
print(fmt % ('', '', '', '--------------------'))
print(fmt % ('', '', 'subtotal', total_before_tax))

tax = (tax_rate * total_before_tax).quantize(D('0.00'))
print(fmt % ('', '', 'Tax', tax))

total = total_before_tax + tax
print(fmt % ('', '', '', '--------------------'))
print(fmt % ('', '', 'Total', total))
Task: Currency








VB: Public Sub currency_task()
    
    Dim number_of_hamburgers As Variant
    number_of_hamburgers = CDec(4E+15)
    Dim price_of_hamburgers As Currency
    price_of_hamburgers = 5.5
    
    Dim number_of_milkshakes As Integer
    number_of_milkshakes = 2
    Dim price_of_milkshakes As Currency
    price_of_milkshakes = 2.86
    
    Dim tax_rate As Single
    tax_rate = 0.0765
    
    Dim total_price_before_tax As Variant
    total_price_before_tax = number_of_hamburgers * price_of_hamburgers
    total_price_before_tax = total_price_before_tax + number_of_milkshakes * price_of_milkshakes
    Debug.Print "Total price before tax "; Format(total_price_before_tax, "Currency")
    
    Dim tax As Variant
    tax = total_price_before_tax * tax_rate
    Debug.Print "Tax "; Format(tax, "Currency")
    
    Debug.Print "Total with tax "; Format(total_price_before_tax + tax, "Currency")
End Sub
Task: Currency




Go: package main

import (
    "fmt"
    "log"
    "math/big"
)


type DC int64

func (dc DC) String() string {
    d := dc / 100
    if dc < 0 {
        dc = -dc
    }
    return fmt.Sprintf("%d.%02d", d, dc%100)
}


func (dc DC) Extend(n int) DC {
    return dc * DC(n)
}

var one = big.NewInt(1)
var hundred = big.NewRat(100, 1)


func ParseDC(s string) (DC, bool) {
    r, ok := new(big.Rat).SetString(s)
    if !ok {
        return 0, false
    }
    r.Mul(r, hundred)
    if r.Denom().Cmp(one) != 0 {
        return 0, false
    }
    return DC(r.Num().Int64()), true
}


type TR struct {
    *big.Rat
}
func NewTR() TR {
    return TR{new(big.Rat)}
}


func (tr TR) SetString(s string) (TR, bool) {
    if _, ok := tr.Rat.SetString(s); !ok {
        return TR{}, false
    }
    return tr, true
}

var half = big.NewRat(1, 2)


func (tr TR) Tax(dc DC) DC {
    r := big.NewRat(int64(dc), 1)
    r.Add(r.Mul(r, tr.Rat), half)
    return DC(new(big.Int).Div(r.Num(), r.Denom()).Int64())
}

func main() {
    hamburgerPrice, ok := ParseDC("5.50")
    if !ok {
        log.Fatal("Invalid hamburger price")
    }
    milkshakePrice, ok := ParseDC("2.86")
    if !ok {
        log.Fatal("Invalid milkshake price")
    }
    taxRate, ok := NewTR().SetString("0.0765")
    if !ok {
        log.Fatal("Invalid tax rate")
    }

    totalBeforeTax := hamburgerPrice.Extend(4000000000000000) +
        milkshakePrice.Extend(2)
    tax := taxRate.Tax(totalBeforeTax)
    total := totalBeforeTax + tax

    fmt.Printf("Total before tax: %22s\n", totalBeforeTax)
    fmt.Printf("             Tax: %22s\n", tax)
    fmt.Printf("           Total: %22s\n", total)
}
Task: Currency

C: 	mpf_set_d(burgerUnitPrice,5.50);
	mpf_set_d(milkshakePrice,2 * 2.86);
	mpf_set_d(burgerNum,4000000000000000);
	mpf_set_d(milkshakeNum,2);









COBOL:        >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. currency-example.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  Burger-Price                        CONSTANT 5.50.
01  Milkshake-Price                     CONSTANT 2.86.
01  num-burgers                         PIC 9(18) VALUE 4000000000000000.
01  num-milkshakes                      PIC 9(18) VALUE 2.
01  tax                                 PIC 9(18)V99.
01  tax-edited                          PIC $(17)9.99.
01  Tax-Rate                            CONSTANT 7.65.
01  total                               PIC 9(18)V99.
01  total-edited                        PIC $(17)9.99.

PROCEDURE DIVISION.
    COMPUTE total rounded, total-edited rounded =
        num-burgers * Burger-Price + num-milkshakes * Milkshake-Price
    DISPLAY "Total before tax: " total-edited

    COMPUTE tax rounded, tax-edited rounded = total * (Tax-Rate / 100)
    DISPLAY "             Tax: " tax-edited

    ADD tax TO total GIVING total-edited rounded
    DISPLAY "  Total with tax: " total-edited
    .
END PROGRAM currency-example.
Task: Currency



C#: using System;
using System.Collections.Generic;

namespace Currency
{
    class Program
    {
        static void Main(string[] args)
        {
            MenuItem hamburger = new MenuItem() { Name = "Hamburger", Price = 5.5M };
            MenuItem milkshake = new MenuItem() { Name = "Milkshake", Price = 2.86M };

            IList<CartItem> cart = new List<CartItem>();
            cart.Add(new CartItem() { item = hamburger, quantity = 4000000000000000 });
            cart.Add(new CartItem() { item = milkshake, quantity = 2 });

            decimal total = CalculateTotal(cart);

            Console.WriteLine(string.Format("Total before tax: {0:C}", total));

            
            decimal tax = total * 0.0765M;

            Console.WriteLine(string.Format("Tax: {0:C}", tax));

            total += tax;

            Console.WriteLine(string.Format("Total with tax: {0:C}", total));
        }

        private static decimal CalculateTotal(IList<CartItem> cart)
        {
            decimal total = 0M;

            foreach (CartItem item in cart)
            {
                total += item.quantity * item.item.Price;
            }

            return total;
        }

        private struct MenuItem
        {
            public string Name { get; set; }
            public decimal Price { get; set; }
        }

        private struct CartItem
        {
            public MenuItem item { get; set; }
            public decimal quantity { get; set; }
        }
    }
}







COBOL:        >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. currency-example.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  Burger-Price                        CONSTANT 5.50.
01  Milkshake-Price                     CONSTANT 2.86.
01  num-burgers                         PIC 9(18) VALUE 4000000000000000.
01  num-milkshakes                      PIC 9(18) VALUE 2.
01  tax                                 PIC 9(18)V99.
01  tax-edited                          PIC $(17)9.99.
01  Tax-Rate                            CONSTANT 7.65.
01  total                               PIC 9(18)V99.
01  total-edited                        PIC $(17)9.99.

PROCEDURE DIVISION.
    COMPUTE total rounded, total-edited rounded =
        num-burgers * Burger-Price + num-milkshakes * Milkshake-Price
    DISPLAY "Total before tax: " total-edited

    COMPUTE tax rounded, tax-edited rounded = total * (Tax-Rate / 100)
    DISPLAY "             Tax: " tax-edited

    ADD tax TO total GIVING total-edited rounded
    DISPLAY "  Total with tax: " total-edited
    .
END PROGRAM currency-example.
Task: Currency





Java: import java.math.*;
import java.util.*;

public class Currency {
    final static String taxrate = "7.65";

    enum MenuItem {

        Hamburger("5.50"), Milkshake("2.86");

        private MenuItem(String p) {
            price = new BigDecimal(p);
        }

        public final BigDecimal price;
    }

    public static void main(String[] args) {
        Locale.setDefault(Locale.ENGLISH);

        MathContext mc = MathContext.DECIMAL128;

        Map<MenuItem, BigDecimal> order = new HashMap<>();
        order.put(MenuItem.Hamburger, new BigDecimal("4000000000000000"));
        order.put(MenuItem.Milkshake, new BigDecimal("2"));

        BigDecimal subtotal = BigDecimal.ZERO;
        for (MenuItem it : order.keySet())
            subtotal = subtotal.add(it.price.multiply(order.get(it), mc));

        BigDecimal tax = new BigDecimal(taxrate, mc);
        tax = tax.divide(new BigDecimal("100"), mc);
        tax = subtotal.multiply(tax, mc);

        System.out.printf("Subtotal: %20.2f%n", subtotal);
        System.out.printf("     Tax: %20.2f%n", tax);
        System.out.printf("   Total: %20.2f%n", subtotal.add(tax));
    }
}





COBOL:        >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. currency-example.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  Burger-Price                        CONSTANT 5.50.
01  Milkshake-Price                     CONSTANT 2.86.
01  num-burgers                         PIC 9(18) VALUE 4000000000000000.
01  num-milkshakes                      PIC 9(18) VALUE 2.
01  tax                                 PIC 9(18)V99.
01  tax-edited                          PIC $(17)9.99.
01  Tax-Rate                            CONSTANT 7.65.
01  total                               PIC 9(18)V99.
01  total-edited                        PIC $(17)9.99.

PROCEDURE DIVISION.
    COMPUTE total rounded, total-edited rounded =
        num-burgers * Burger-Price + num-milkshakes * Milkshake-Price
    DISPLAY "Total before tax: " total-edited

    COMPUTE tax rounded, tax-edited rounded = total * (Tax-Rate / 100)
    DISPLAY "             Tax: " tax-edited

    ADD tax TO total GIVING total-edited rounded
    DISPLAY "  Total with tax: " total-edited
    .
END PROGRAM currency-example.
Task: Currency







Python: from decimal import Decimal as D
from collections import namedtuple

Item = namedtuple('Item', 'price, quant')

items = dict( hamburger=Item(D('5.50'), D('4000000000000000')),
              milkshake=Item(D('2.86'), D('2')) )
tax_rate = D('0.0765')

fmt = "%-10s %8s %18s %22s"
print(fmt % tuple('Item Price Quantity Extension'.upper().split()))

total_before_tax = 0
for item, (price, quant) in sorted(items.items()):
    ext = price * quant
    print(fmt % (item, price, quant, ext))
    total_before_tax += ext
print(fmt % ('', '', '', '--------------------'))
print(fmt % ('', '', 'subtotal', total_before_tax))

tax = (tax_rate * total_before_tax).quantize(D('0.00'))
print(fmt % ('', '', 'Tax', tax))

total = total_before_tax + tax
print(fmt % ('', '', '', '--------------------'))
print(fmt % ('', '', 'Total', total))



COBOL:        >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. currency-example.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  Burger-Price                        CONSTANT 5.50.
01  Milkshake-Price                     CONSTANT 2.86.
01  num-burgers                         PIC 9(18) VALUE 4000000000000000.
01  num-milkshakes                      PIC 9(18) VALUE 2.
01  tax                                 PIC 9(18)V99.
01  tax-edited                          PIC $(17)9.99.
01  Tax-Rate                            CONSTANT 7.65.
01  total                               PIC 9(18)V99.
01  total-edited                        PIC $(17)9.99.

PROCEDURE DIVISION.
    COMPUTE total rounded, total-edited rounded =
        num-burgers * Burger-Price + num-milkshakes * Milkshake-Price
    DISPLAY "Total before tax: " total-edited

    COMPUTE tax rounded, tax-edited rounded = total * (Tax-Rate / 100)
    DISPLAY "             Tax: " tax-edited

    ADD tax TO total GIVING total-edited rounded
    DISPLAY "  Total with tax: " total-edited
    .
END PROGRAM currency-example.
Task: Currency








VB: Public Sub currency_task()
    
    Dim number_of_hamburgers As Variant
    number_of_hamburgers = CDec(4E+15)
    Dim price_of_hamburgers As Currency
    price_of_hamburgers = 5.5
    
    Dim number_of_milkshakes As Integer
    number_of_milkshakes = 2
    Dim price_of_milkshakes As Currency
    price_of_milkshakes = 2.86
    
    Dim tax_rate As Single
    tax_rate = 0.0765
    
    Dim total_price_before_tax As Variant
    total_price_before_tax = number_of_hamburgers * price_of_hamburgers
    total_price_before_tax = total_price_before_tax + number_of_milkshakes * price_of_milkshakes
    Debug.Print "Total price before tax "; Format(total_price_before_tax, "Currency")
    
    Dim tax As Variant
    tax = total_price_before_tax * tax_rate
    Debug.Print "Tax "; Format(tax, "Currency")
    
    Debug.Print "Total with tax "; Format(total_price_before_tax + tax, "Currency")
End Sub


COBOL:        >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. currency-example.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  Burger-Price                        CONSTANT 5.50.
01  Milkshake-Price                     CONSTANT 2.86.
01  num-burgers                         PIC 9(18) VALUE 4000000000000000.
01  num-milkshakes                      PIC 9(18) VALUE 2.
01  tax                                 PIC 9(18)V99.
01  tax-edited                          PIC $(17)9.99.
01  Tax-Rate                            CONSTANT 7.65.
01  total                               PIC 9(18)V99.
01  total-edited                        PIC $(17)9.99.

PROCEDURE DIVISION.
    COMPUTE total rounded, total-edited rounded =
        num-burgers * Burger-Price + num-milkshakes * Milkshake-Price
    DISPLAY "Total before tax: " total-edited

    COMPUTE tax rounded, tax-edited rounded = total * (Tax-Rate / 100)
    DISPLAY "             Tax: " tax-edited

    ADD tax TO total GIVING total-edited rounded
    DISPLAY "  Total with tax: " total-edited
    .
END PROGRAM currency-example.
Task: Currency




Go: package main

import (
    "fmt"
    "log"
    "math/big"
)


type DC int64

func (dc DC) String() string {
    d := dc / 100
    if dc < 0 {
        dc = -dc
    }
    return fmt.Sprintf("%d.%02d", d, dc%100)
}


func (dc DC) Extend(n int) DC {
    return dc * DC(n)
}

var one = big.NewInt(1)
var hundred = big.NewRat(100, 1)


func ParseDC(s string) (DC, bool) {
    r, ok := new(big.Rat).SetString(s)
    if !ok {
        return 0, false
    }
    r.Mul(r, hundred)
    if r.Denom().Cmp(one) != 0 {
        return 0, false
    }
    return DC(r.Num().Int64()), true
}


type TR struct {
    *big.Rat
}
func NewTR() TR {
    return TR{new(big.Rat)}
}


func (tr TR) SetString(s string) (TR, bool) {
    if _, ok := tr.Rat.SetString(s); !ok {
        return TR{}, false
    }
    return tr, true
}

var half = big.NewRat(1, 2)


func (tr TR) Tax(dc DC) DC {
    r := big.NewRat(int64(dc), 1)
    r.Add(r.Mul(r, tr.Rat), half)
    return DC(new(big.Int).Div(r.Num(), r.Denom()).Int64())
}

func main() {
    hamburgerPrice, ok := ParseDC("5.50")
    if !ok {
        log.Fatal("Invalid hamburger price")
    }
    milkshakePrice, ok := ParseDC("2.86")
    if !ok {
        log.Fatal("Invalid milkshake price")
    }
    taxRate, ok := NewTR().SetString("0.0765")
    if !ok {
        log.Fatal("Invalid tax rate")
    }

    totalBeforeTax := hamburgerPrice.Extend(4000000000000000) +
        milkshakePrice.Extend(2)
    tax := taxRate.Tax(totalBeforeTax)
    total := totalBeforeTax + tax

    fmt.Printf("Total before tax: %22s\n", totalBeforeTax)
    fmt.Printf("             Tax: %22s\n", tax)
    fmt.Printf("           Total: %22s\n", total)
}






COBOL:        >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. currency-example.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  Burger-Price                        CONSTANT 5.50.
01  Milkshake-Price                     CONSTANT 2.86.
01  num-burgers                         PIC 9(18) VALUE 4000000000000000.
01  num-milkshakes                      PIC 9(18) VALUE 2.
01  tax                                 PIC 9(18)V99.
01  tax-edited                          PIC $(17)9.99.
01  Tax-Rate                            CONSTANT 7.65.
01  total                               PIC 9(18)V99.
01  total-edited                        PIC $(17)9.99.

PROCEDURE DIVISION.
    COMPUTE total rounded, total-edited rounded =
        num-burgers * Burger-Price + num-milkshakes * Milkshake-Price
    DISPLAY "Total before tax: " total-edited

    COMPUTE tax rounded, tax-edited rounded = total * (Tax-Rate / 100)
    DISPLAY "             Tax: " tax-edited

    ADD tax TO total GIVING total-edited rounded
    DISPLAY "  Total with tax: " total-edited
    .
END PROGRAM currency-example.