{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d698094b",
   "metadata": {},
   "source": [
    "# 04-16 · Decimal i pieniądze\n",
    "\n",
    "Praktyka do sekcji [„Decimal jest dokładną arytmetyką dziesiętną”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9047592d",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Zrozum różnicę między Decimal(str) a Decimal(float)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84b709ee",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8df0fd0d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:43.969209Z",
     "iopub.status.busy": "2026-08-16T10:03:43.969029Z",
     "iopub.status.idle": "2026-08-16T10:03:43.985468Z",
     "shell.execute_reply": "2026-08-16T10:03:43.985092Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.3\n"
     ]
    }
   ],
   "source": [
    "from decimal import Decimal\n",
    "print(Decimal(\"0.1\") + Decimal(\"0.2\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b9da435",
   "metadata": {},
   "source": [
    "## Eksperyment 1\n",
    "\n",
    "Porównaj Decimal ze sznurka i Decimal z float."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8492bcad",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:43.986733Z",
     "iopub.status.busy": "2026-08-16T10:03:43.986618Z",
     "iopub.status.idle": "2026-08-16T10:03:43.988882Z",
     "shell.execute_reply": "2026-08-16T10:03:43.988423Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19.99\n",
      "19.989999999999998436805981327779591083526611328125\n"
     ]
    }
   ],
   "source": [
    "from decimal import Decimal\n",
    "print(Decimal(\"19.99\"))\n",
    "print(Decimal(19.99))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dde36295",
   "metadata": {},
   "source": [
    "## Podstawowa praktyka zadań ★\n",
    "\n",
    "Oblicz kwotę zakupu: cena 24,99, ilość 3 – używając Decimal utworzonego z wiersza."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3fc1263b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:43.989797Z",
     "iopub.status.busy": "2026-08-16T10:03:43.989694Z",
     "iopub.status.idle": "2026-08-16T10:03:43.991841Z",
     "shell.execute_reply": "2026-08-16T10:03:43.991399Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "74.97\n"
     ]
    }
   ],
   "source": [
    "from decimal import Decimal\n",
    "price = Decimal(\"24.99\")\n",
    "quantity = 3\n",
    "print(price * quantity)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
