{"id":22927526,"url":"https://github.com/kpym/decstr","last_synced_at":"2025-04-01T15:43:24.102Z","repository":{"id":257195989,"uuid":"857367220","full_name":"kpym/decstr","owner":"kpym","description":"A golang package to work with decimal strings.","archived":false,"fork":false,"pushed_at":"2025-03-22T08:27:33.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T09:25:11.304Z","etag":null,"topics":["go","go-module","go-package","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kpym.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-14T13:21:08.000Z","updated_at":"2025-03-22T08:27:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"43d65ff0-3fc0-488a-89eb-096633da87fb","html_url":"https://github.com/kpym/decstr","commit_stats":null,"previous_names":["kpym/decstr"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpym%2Fdecstr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpym%2Fdecstr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpym%2Fdecstr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpym%2Fdecstr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kpym","download_url":"https://codeload.github.com/kpym/decstr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246666785,"owners_count":20814575,"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":["go","go-module","go-package","golang"],"created_at":"2024-12-14T09:14:56.466Z","updated_at":"2025-04-01T15:43:24.083Z","avatar_url":"https://github.com/kpym.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# decstr\n\n`decstr` is a Golang package to handle decimal strings. It provides utilities to normalize, check, detect formats, and convert decimal strings, without relying on external dependencies.\n\n## Features\n\n- Normalize decimal strings:\n  - Removes grouping separators.\n  - Standardizes the decimal separator to `.` (dot).\n  - Removes leading zeros, trailing zeros, and trailing decimal separators for integers.\n  \n- Detect decimal format (grouping separator, decimal separator, and grouping style).\n- Convert decimal strings to a specified format.\n\n## Example\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"github.com/kpym/decstr\"\n)\n\nfunc main() {\n    decimal := \"1'234'567,89\"\n\n    // Normalize example\n    normalized := decstr.Normalize(decimal)\n    fmt.Println(\"Normalized:\", normalized) // 1234567.89\n\n    // Detect format example\n    format, ok := decstr.DetectFormat(decimal)\n    fmt.Println(\"Detected format:\", format, \"ok:\", ok) // Detected format: {`,`, `'`, standard} ok: true\n    \n\t// Convert example\n    df := decstr.DecimalFormat{Point: '.', Group: ' ', Standard: false}\n    converted, ok := df.Convert(decimal)\n    fmt.Println(\"Converted:\", converted, \"ok:\", ok) // Converted: 12 34 567.89 ok: true\n}\n```\n\n## Functions\n\nAll functions accept both `string` or `[]byte` as input and return results in the same type.\nIn what follows, only \"string\" is used for simplicity.\n\n### `Normalize`\nNormalizes a decimal string:\n- No grouping separators.\n- Decimal separator is `.` (dot).\n- No leading or trailing zeros (and no trailing decimal for integers).\n  \nIf the input string is not a valid decimal, it returns the string as-is.\n### `NormalizeCheck`\nSame as `Normalize`, but also returns a boolean indicating whether the string was normalized.\n\n### `IsNormalized`\nChecks if the decimal string is normalized.\n\n### `DetectFormat`\nDetects the decimal format:\n- Returns the decimal separator.\n- Returns the grouping separator (if any).\n- Indicates whether the grouping is standard (3 digits per group) or non-standard (first 3 digits, then 2 per group).\n\n### `Convert`\nConverts a decimal string to the specified format.\n\n## Documentation\n\nThe package documentation is available at [pkg.go.dev](https://pkg.go.dev/github.com/kpym/decstr).\n\n## LICENSE\n\nThis package is released under the [MIT License](LICENSE).\n\n## Decimal Format\n\nPossible decimal writings from [Wikipedia](https://en.wikipedia.org/wiki/Decimal_separator):\n\n- standard grouping (by 3)\n  - `1,234,567.89` : Australia, Cambodia, Canada (English-speaking; unofficial), China, Cyprus (currency numbers), Hong Kong, Iran, Ireland, Israel, Japan, Korea, Macau (in Chinese and English text), Malaysia, Mexico, Namibia, New Zealand, Pakistan, Peru (currency numbers), Philippines, Singapore, South Africa (English-speaking; unofficial), Taiwan, Thailand, United Kingdom and other Commonwealth states except Mozambique, United States.\n  - `1 234 567.89` : Canada (English-speaking; official), China, Estonia (currency numbers), Hong Kong (in education), Mexico, Namibia, South Africa (English-speaking; unofficial), Sri Lanka, Switzerland (in federal texts for currency numbers only), United Kingdom (in education), United States (in education). SI style (English version) but SI doesn't include currency.\n  - `1 234 567,89` : Albania, Belgium (French), Brazil, Bulgaria, Canada (French-speaking), Costa Rica, Croatia, Czech Republic, Estonia, Finland, France, Hungary, Italy (in education), Latin America, Latin Europe, Latvia, Lithuania, Macau (in Portuguese text), Mozambique, Norway, Peru, Poland, Portugal, Russia, Serbia (informal), Slovakia, Slovenia, South Africa (official), Spain (official use since 2010, according to the RAE and CSIC), Sweden, Switzerland (in federal texts, except currency numbers[56]), Ukraine, Vietnam (in education). SI style (French version) but SI doesn't include currency.\n  - `1.234.567,89` : Austria, Belgium (Dutch), Bosnia and Herzegovina, Brazil (informal and in technology), Chile, Colombia, Croatia (in bookkeeping and technology), Denmark, Germany, Greece, Indonesia, Italy, Latin America (informal), Netherlands, Romania, Slovenia, Serbia, Spain (used until 2010, inadvisable use according to the RAE and CSIC), Turkey, Uruguay, Vietnam.\n  - `1,234,567·89` : Malaysia, Malta, Philippines (uncommon today), Singapore, Taiwan, United Kingdom (older, typically handwritten; in education)\n  - `1'234'567.89` : Switzerland (computing), Liechtenstein.\n  - `1'234'567,89` : Switzerland (handwriting), Italy (handwriting).\n  - `1.234.567'89` : Spain (handwriting, used until 1980s).\n- non standard grouping (3, then by 2)\n  - `12,34,567.89` : Bangladesh, India, Nepal, Pakistan\n  - `12 34 567.89` : Bangladesh, India, Nepal, Pakistan\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpym%2Fdecstr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkpym%2Fdecstr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpym%2Fdecstr/lists"}