{"id":28430948,"url":"https://github.com/elixir-cldr/cldr_print","last_synced_at":"2025-07-04T17:32:10.565Z","repository":{"id":35004880,"uuid":"173512980","full_name":"elixir-cldr/cldr_print","owner":"elixir-cldr","description":"CLDR compatible localised printf","archived":false,"fork":false,"pushed_at":"2023-08-29T07:50:03.000Z","size":179,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-05T14:39:38.108Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elixir-cldr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-03T00:12:34.000Z","updated_at":"2022-12-09T17:50:06.000Z","dependencies_parsed_at":"2022-08-08T03:16:13.514Z","dependency_job_id":null,"html_url":"https://github.com/elixir-cldr/cldr_print","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/elixir-cldr/cldr_print","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-cldr%2Fcldr_print","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-cldr%2Fcldr_print/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-cldr%2Fcldr_print/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-cldr%2Fcldr_print/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-cldr","download_url":"https://codeload.github.com/elixir-cldr/cldr_print/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-cldr%2Fcldr_print/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263588240,"owners_count":23484889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-05T14:30:36.560Z","updated_at":"2025-07-04T17:32:10.554Z","avatar_url":"https://github.com/elixir-cldr.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cldr Print\n\nProvides [printf and sprintf](http://man7.org/linux/man-pages/man3/printf.3.html) functions for Elixir that are largely compatible with the `C` versions.\n\n## Getting Started\n\n`Cldr.Print.printf/3`, `Cldr.Print.sprintf/3` and `Cldr.Print.lprintf/3` operate on a format string and a list of arguments to produce a formatted output.  The differences are:\n\n* `Cldr.Print.printf/3` outputs to a device specified under the option key `:device` with `:stdout` as the default\n* `Cldr.Print.sprintf/3` returns an `{:ok, string}` tuple or an `{:error, {exception, reason}}` tuple.\n* `Cldr.Print.lprintf/3` returns an `{:ok, io_list}` tuple or an `{:error, {exception, reason}}` tuple.\n\nThere are also `!` bang versions of these functions which will return the result unwrapped or raise an exception if there is an error.\n\n## Examples\n\nHere are some examples to help get started if you are unfamiliar with the `C` versions of these functions.\n\n### Controlling Integer Width\n\nThe `%3d` specifier is used with integers where the `3` represents the width in graphemes of the final formatted string. These example define a minimum width of three spaces which, by default, will be right-justified:\n\n| Function call                     | Result            |\n| --------------------------------- | ----------------: |\n| printf!(\"%3d\", 0)                 |\t0                 |\n| printf!(\"%3d\", 123456789)         |\t123456789         |\n| printf!(\"%3d\", -10)\t              | -10               |\n| printf!(\"%3d\", -123456789)        | -123456789        |\n\n### Left-justifying  with the `-` flag\n\nTo left-justify an integer add a minus sign `-` after the `%` symbol:\n\n| Function call                     | Result            |\n| --------------------------------- | :---------------- |\n| printf!(\"%-3d\", 0)                | 0                 |\n| printf!(\"%-3d\", 123456789)        | 123456789         |\n| printf!(\"%-3d\", -10)              | -10               |\n| printf!(\"%-3d\", -123456789)       | -123456789        |\n\n### Zero-fill flag\n\nTo zero-fill the result add a zero `0` after the `%` symbol:\n\n| Function call                     | Result            |\n| --------------------------------- | ----------------: |\n| printf(\"%03d\", 0)                 | 000               |\n| printf(\"%03d\", 1)                 | 001               |\n| printf(\"%03d\", 123456789)         | 123456789         |\n| printf(\"%03d\", -10)               | -10               |\n| printf(\"%03d\", -123456789)        | -123456789        |\n\n### Integer formatting summary\n\nHere are some further examples including a minimum width specification, left-justified, zero-filled, as well as a plus sign for positive numbers.\n\n| Description                             | Function call                | Result            |\n| --------------------------------------- | ---------------------------- | ----------------: |\n| At least five wide\t                    | printf(\"'%5d'\", 10)          | '   10'           |\n| At least five-wide, left-justified      |\tprintf(\"'%-5d'\", 10)         | '10   '           |\n| At least five-wide, zero-filled\t        | printf(\"'%05d'\", 10)         | '00010'           |\n| At least five-wide, with a plus sign\t  | printf(\"'%+5d'\", 10)         | '  +10'           |\n| Five-wide, plus sign, left-justified\t  | printf(\"'%-+5d'\", 10)        | '+10  '           |\n\n### Floating Point Formatting\n\nHere are several examples showing how to format floating-point numbers:\n\n| Description                                 | Function call                | Result            |\n| ------------------------------------------- | ---------------------------- | ----------------: |\n| Print one position after the decimal\t      | printf(\"'%.1f'\", 10.3456)    | '10.3'            |\n| Two positions after the decimal\t            | printf(\"'%.2f'\", 10.3456)    | '10.35'           |\n| Eight-wide, two positions after the decimal\t| printf(\"'%8.2f'\", 10.3456)   | '   10.35'        |\n| Eight-wide, four positions after the decimal| printf(\"'%8.4f'\", 10.3456)   | ' 10.3456'        |\n| Eight-wide, two positions after the decimal, zero-filled | printf(\"'%08.2f'\", 10.3456) | '00010.35' |\n| Eight-wide, two positions after the decimal, left-justified\t| printf(\"'%-8.2f'\", 10.3456) | '10.35   ' |\n| Printing a much larger number with that same format\t| printf(\"'%-8.2f'\",101234567.3456) | '101234567.35' |\n\n### String Formatting\n\nHere are some examples of string formatting:\n\n| Description                                 | Function call                | Result            |\n| ------------------------------------------- | ---------------------------- | ----------------: |\n| A simple string\t                            | printf(\"'%s'\", \"Hello\")      | 'Hello'           |\n| A string with a minimum length\t            | printf(\"'%10s'\", \"Hello\")    | '     Hello'      |\n| Minimum length, left-justified\t            | printf(\"'%-10s'\", \"Hello\")   | 'Hello     '      |\n\n## Format Specification\n\nThe format is a string which contains two types of objects:\nplain characters, which are simply copied to standard output and format\nspecifications, each of which causes printing of the next successive argument.\n\nEach format specification is introduced by the percent character (`%`).\nThe remainder of the format specification includes, in the following order:\n\n* Optional format flags\n* Optional field width\n* Optional precision\n* Required format type\n\nThe can be represented as:\n```\n%[flags][width][.precision]format_type\n```\n\n### Format flags\n\nZero or more of the following flags:\n\n| Flag  | Description                                                                    |\n| ----- | -------------------------------------------------------------------------------|\n| #     | A `#` character specifying that the value should be printed in an alternate form. For `b`, `c`, `d`, `s` and `u` formats, this option has no effect. For the `o` formats the precision of the number is increased to force the first character of the output string to a zero. For the `x` (`X`) format, a non-zero result has the string `0x` (`0X`) prepended to it. For `a`, `A`, `e`, `E`, `f`, `F`, `g` and `G` formats, the result will always contain a decimal point, even if no digits follow the point (normally, a decimal point only appears in the results of those formats if a digit follows the decimal point). For `g` and `G` formats, trailing zeros are not removed from the result as they would otherwise be. |\n| -     | A minus sign `-' which specifies left adjustment of the output in the indicated field. |\n| +     | A `+` character specifying that there should always be a sign placed before the number when using signed formats. |\n| space | A space character specifying that a blank should be left before a positive number for a signed format. A `+` overrides a space if both are used. |\n| 0     | A zero `0` character indicating that zero-padding should be used rather than blank-padding.  A `-` overrides a `0` if both are used. Is not applied for `o`, `x`, `X` formats. |\n| '     | Formats a number with digit grouping applied. The group size and grouping character are determined based upon the current processes locale or the `:locale` option to `printf/3` if provided. Is not applied for formats `o`, `x`, `X` formats. |\n| I     | Formats a number using the native number system digits of the current processes locale or the `:locale` option to `printf/3` if provided. The option `:number_system` if provided takes precedence over this flag. |\n\n### Field Width\n\nAn optional digit string specifying a field width; if the output string has fewer bytes than the field\nwidth it will be blank-padded on the left (or right, if the left-adjustment indicator has been given)\nto make up the field width (note that a leading zero is a flag, but an embedded zero is part of a\nfield width).\n\n### Precision\n\nAn optional period, `.`, followed by an optional digit string giving a precision which specifies the\nnumber of digits to appear after the decimal point, for `e` and `f` formats, or the maximum number of\ngraphemes to be printed from a string. If the digit string is missing, the precision is treated as zero.\n\n### Format Type\n\nA character which indicates the type of format to use (one of `diouxXfFeEgGaAs`).  The uppercase\nformats differ from their lowercase counterparts only in that the output of the former is entirely in\nuppercase.\n\n| Format | Description                                                                    |\n| ------ | -------------------------------------------------------------------------------|\n| diouXx | The argument is printed as a signed decimal (d or i), unsigned octal, unsigned decimal, or unsigned hexadecimal (X or x), respectively. |\n| fF     | The argument is printed in the style `[-]ddd.ddd` where the number of d's after the decimal point is equal to the precision specification for the argument.  If the precision is missing, 6 digits are given; if the precision is explicitly 0, no digits and no decimal point are printed.  The values infinity and NaN are printed as `inf' and `nan', respectively. |\n| eE     | The argument is printed in the style e `[-d.ddd+-dd]` where there is one digit before the decimal point and the number after is equal to the precision specification for the argument; when the precision is missing, 6 digits are produced.  The values infinity and NaN are printed as `inf` and `nan`, respectively. |\n| gG     | The argument is printed in style f or e (or in style E for a G format code), with the precision specifying the number of significant digits. The style used depends on the value converted: style e will be used only if the exponent resulting from the conversion is less than -4 or greater than the precision. Trailing zeroes are removed from the result; a decimal point appears only if it is followed by a digit. |\n| aA     | The argument is printed in style `[-h.hhh+-pd]` where there is one digit before the hexadecimal point and the number after is equal to the precision specification for the argument; when the precision is missing, enough digits are produced to convey the argument's exact double-precision floating-point representation.  The values infinity and NaN are printed as `inf` and `nan`, respectively. |\n| s      | Graphemes from the string argument are printed until the end is reached or until the number of graphemes indicated by the precision specification is reached; however if the precision is 0 or missing, the string is printed entirely. |\n| %      | Print a `%`; no argument is used. |\n\n### Notes\n\n* The grouping separator, decimal point and exponent characters are defined in the current process's locale or as specified in the `:locale` option to `printf/3`.\n\n* In no case does a non-existent or small field width cause truncation of a field; padding takes place only if the specified field width exceeds the actual width.\n\n## Todo\n\n* [ ] Formats `a` and `A` aren't implemented\n\n* [ ] The `#` is not validated for a, A, e, E, f, F, g and G formats. There seems to be some inconsistent implementations around that need further investigation\n\n* [ ] The *space* flag is not implemented\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:ex_cldr_print, \"~\u003e 0.3.0\"}\n  ]\nend\n```\nThe documentation can be found at [https://hexdocs.pm/ex_cldr_print](https://hexdocs.pm/ex_cldr_print).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-cldr%2Fcldr_print","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-cldr%2Fcldr_print","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-cldr%2Fcldr_print/lists"}