{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "f = 123.456" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "123\n" ] } ], "source": [ "print(round(f))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "print(type(round(f)))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "123.5\n" ] } ], "source": [ "print(round(f, 1))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "123.46\n" ] } ], "source": [ "print(round(f, 2))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "120.0\n" ] } ], "source": [ "print(round(f, -1))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "100.0\n" ] } ], "source": [ "print(round(f, -2))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "123.0\n" ] } ], "source": [ "print(round(f, 0))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "print(type(round(f, 0)))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": true }, "outputs": [], "source": [ "i = 99518" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "99518\n" ] } ], "source": [ "print(round(i))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "99518\n" ] } ], "source": [ "print(round(i, 2))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "99520\n" ] } ], "source": [ "print(round(i, -1))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "99500\n" ] } ], "source": [ "print(round(i, -2))" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "100000\n" ] } ], "source": [ "print(round(i, -3))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.4 => 0\n", "0.5 => 0\n", "0.6 => 1\n" ] } ], "source": [ "print('0.4 =>', round(0.4))\n", "print('0.5 =>', round(0.5))\n", "print('0.6 =>', round(0.6))" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4 => 0\n", "5 => 0\n", "6 => 10\n" ] } ], "source": [ "print('4 =>', round(4, -1))\n", "print('5 =>', round(5, -1))\n", "print('6 =>', round(6, -1))" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.5 => 0\n", "1.5 => 2\n", "2.5 => 2\n", "3.5 => 4\n", "4.5 => 4\n" ] } ], "source": [ "print('0.5 =>', round(0.5))\n", "print('1.5 =>', round(1.5))\n", "print('2.5 =>', round(2.5))\n", "print('3.5 =>', round(3.5))\n", "print('4.5 =>', round(4.5))" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.05 => 0.1\n", "0.15 => 0.1\n", "0.25 => 0.2\n", "0.35 => 0.3\n", "0.45 => 0.5\n" ] } ], "source": [ "print('0.05 =>', round(0.05, 1))\n", "print('0.15 =>', round(0.15, 1))\n", "print('0.25 =>', round(0.25, 1))\n", "print('0.35 =>', round(0.35, 1))\n", "print('0.45 =>', round(0.45, 1))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }