#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Exacte decimale optelling met het Decimal-type. Hoofdstuk: 29 — Decimalen in Python & C """ from decimal import Decimal, getcontext getcontext().prec = 28 x = Decimal("0.1") y = Decimal("0.2") z = x + y print("x =", x) print("y =", y) print("x + y =", z) print("Is x + y exact 0.3?", z == Decimal("0.3"))