{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Numeric Rounding Function\nGiven an array of numbers round it with conditioning formattings.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Author: Fan Wang (fanwangecon.github.io)\nimport pyfan.amto.numeric.round as pyfan_amto_round\nimport numpy as np\nimport matplotlib.pyplot as plt"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Common rounding\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# construct data inputs\nar_fl_exa = np.array([0.4334, 0.5183, 0.0454, 0.0027, 0.0002])\nls_st_numformated_common = pyfan_amto_round.ff_decimal_rounder(ls_fl_num2format=ar_fl_exa, it_or_dc_round_decimal=2)\nprint(f'{ls_st_numformated_common=}')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Uncommon rounding by number size with fractions\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "dc_round_decimal = {0.001:4, 0.01:3, 0.1:2, float(\"inf\"):2}\nls_st_numformated_uncommon = pyfan_amto_round.ff_decimal_rounder_uncommon(ls_fl_num2format=ar_fl_exa,\n                                                                          dc_round_decimal=dc_round_decimal)\nprint(f'{ls_st_numformated_uncommon=}')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Uncommon rounding by number size test 2 with large numbers\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "ls_fl_num2format = [0.0012345, 0.12345, 12.345, 123.45, 1234.5, 123456.789]\ndc_round_decimal = {0.1:4, 1:3, 100:2, float(\"inf\"):0}\nls_st_numformated_large_uncommon = pyfan_amto_round.ff_decimal_rounder_uncommon(ls_fl_num2format=ls_fl_num2format,\n                                                                                dc_round_decimal=dc_round_decimal)\nprint(f'{ls_st_numformated_large_uncommon=}')\n\n\n# Start Plot\nfig, ax = plt.subplots()\n\n# Text Plot\nax.text(0.5, 0.5, f'{ar_fl_exa}\\n{ls_st_numformated_common=}\\n{dc_round_decimal=}\\n{ls_st_numformated_uncommon=}'\n                  f'\\n\\n{ls_fl_num2format=}\\n{dc_round_decimal=}\\n{ls_st_numformated_large_uncommon=}',\n        horizontalalignment='center',\n        verticalalignment='center',\n        fontsize=10, color='black',\n        transform=ax.transAxes)\n\n# Labeling\nax.set_axis_off()\nplt.show()"
      ]
    }
  ],
  "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.8.5"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}