{ "schema_type": "object", "schema_version": "1.0", "name": "number_to_human", "path": "packages/ree_number/package/ree_number/functions/number_to_human.rb", "mount_as": "fn", "class": "ReeNumber::NumberToHuman", "factory": null, "methods": [ { "doc": "Pretty prints (formats and approximates) a number in a way it\nis more readable by humans (e.g.: 1200000000 becomes \"1.2\nBillion\"). This is useful for numbers that can get very large\n(and too hard to read).\n\nSee number_to_human_size if you want to print a file\nsize.\n\nYou can also define your own unit-quantifier names if you want\nto use other decimal units (e.g.: 1500 becomes \"1.5\nkilometers\", 0.150 becomes \"150 milliliters\", etc). You may\ndefine a wide range of unit quantifiers, even fractional ones\n(centi, deci, mili, etc).\n\n==== Options\n* :locale - Sets the locale to be used for formatting\n (defaults to current locale).\n* :precision - Sets the precision of the number\n (defaults to 3).\n* :significant - If +true+, precision will be the number\n of significant_digits. If +false+, the number of fractional\n digits (defaults to +true+)\n* :round_mode - Determine how rounding is performed\n (defaults to :default. See BigDecimal::mode)\n* :separator - Sets the separator between the\n fractional and integer digits (defaults to \".\").\n* :delimiter - Sets the thousands delimiter (defaults\n to \"\").\n* :strip_insignificant_zeros - If +true+ removes\n insignificant zeros after the decimal separator (defaults to\n +true+)\n* :units - A Hash of unit quantifier names. Or a\n string containing an i18n scope where to find this hash. It\n might have the following keys:\n * *integers*: :unit, :ten,\n :hundred, :thousand, :million,\n :billion, :trillion,\n :quadrillion\n * *fractionals*: :deci, :centi,\n :mili, :micro, :nano,\n :pico, :femto\n* :format - Sets the format of the output string\n (defaults to \"%n %u\"). The field types are:\n * %u - The quantifier (ex.: 'thousand')\n * %n - The number\n==== Examples\n number_to_human(123)\n # => \"123\"\n\n number_to_human(1234)\n # => \"1.23 Thousand\"\n\n number_to_human(12345)\n # => \"12.3 Thousand\"\n\n number_to_human(1234567)\n # => \"1.23 Million\"\n\n number_to_human(1234567890)\n # => \"1.23 Billion\"\n\n number_to_human(1234567890123)\n # => \"1.23 Trillion\"\n\n number_to_human(1234567890123456)\n # => \"1.23 Quadrillion\"\n\n number_to_human(1234567890123456789)\n # => \"1230 Quadrillion\"\n\n number_to_human(489939, precision: 2)\n # => \"490 Thousand\"\n\n number_to_human(489939, precision: 4)\n # => \"489.9 Thousand\"\n\n number_to_human(1234567, precision: 4, significant: false)\n # => \"1.2346 Million\"\n\n number_to_human(1234567, precision: 1, separator: ',', significant: false)\n # => \"1,2 Million\"\n\n number_to_human(500000000, precision: 5)\n # => \"500 Million\"\n\n number_to_human(12345012345, significant: false)\n # => \"12.345 Billion\"\n\nNon-significant zeros after the decimal separator are stripped\nout by default (set :strip_insignificant_zeros to\n+false+ to change that):\n\nnumber_to_human(12.00001)\n# => \"12\"\n\nnumber_to_human(12.00001, strip_insignificant_zeros: false)\n# => \"12.0\"", "throws": [ ], "return": "String", "args": [ { "arg": "number", "type": "Or[Integer, Float, String]" }, { "arg": "opts", "type": "Ksplat[:units? => String, :locale? => Symbol, :format? => String, :precision? => Integer, :significant? => Bool, :strip_insignificant_zeros? => Bool, :separator? => String, :delimiter? => String, :round_mode? => Or[up, down, truncate, half_up, default, half_down, half_even, banker, ceiling, floor]]" } ] } ], "links": [ { "target": "number_to_delimited", "package_name": "ree_number", "as": "number_to_delimited", "imports": [ ] }, { "target": "number_to_rounded", "package_name": "ree_number", "as": "number_to_rounded", "imports": [ ] }, { "target": "round_helper", "package_name": "ree_number", "as": "round_helper", "imports": [ "ROUND_MODES" ] }, { "target": "slice", "package_name": "ree_hash", "as": "slice", "imports": [ ] }, { "target": "t", "package_name": "ree_i18n", "as": "t", "imports": [ ] } ] }