Title: Formatting system: format large numbers with thousands separators (digit grouping) by default · Issue #13590 · PowerShell/PowerShell · GitHub
Open Graph Title: Formatting system: format large numbers with thousands separators (digit grouping) by default · Issue #13590 · PowerShell/PowerShell
X Title: Formatting system: format large numbers with thousands separators (digit grouping) by default · Issue #13590 · PowerShell/PowerShell
Description: Summary of the new feature/enhancement The output formatting system's purpose is to present data to the human reader. (As such - because the formatted output isn't meant for programmatic processing - it isn't part of PowerShell's breakin...
Open Graph Description: Summary of the new feature/enhancement The output formatting system's purpose is to present data to the human reader. (As such - because the formatted output isn't meant for programmatic processing...
X Description: Summary of the new feature/enhancement The output formatting system's purpose is to present data to the human reader. (As such - because the formatted output isn't meant for programmatic pr...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/13590
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Formatting system: format large numbers with thousands separators (digit grouping) by default","articleBody":"## Summary of the new feature/enhancement\r\n\r\nThe output formatting system's purpose is to present data to the _human_ reader.\r\n(As such - because the formatted output isn't meant for _programmatic_ processing - it isn't part of PowerShell's breaking-changes contract.)\r\n\r\nCurrently, large numbers are output without thousands separators, i.e. without grouping the digits for easier comprehension.\r\n\r\nI suggest applying this grouping to all numbers (that aren't explicitly formatted via formatting data):\r\n\r\n```powershell\r\n# WISHFUL THINKING - but you can get a preview with the prototype below.\r\n\r\n# Number by itself (out-of-band formatting)\r\nPS> 1000\r\n1,000\r\n\r\n# Implicit in-band formatting (table or list)\r\nPS> @{ num = 1000 }\r\n\r\nName Value\r\n---- -----\r\nnum 1,000\r\n\r\n# Should also automatically apply to types with explicit formatting data \r\n# (unless number formatting is part of a given list item / table column).\r\n# Note the \"Size\" column.\r\nPS> Get-Item $PROFILE\r\n\r\n Directory: /Users/jdoe/.config/powershell\r\n\r\nUnixMode User Group LastWriteTime Size Name\r\n-------- ---- ----- ------------- ---- ----\r\n-rw-r--r-- jdoe staff 10/23/2019 22:31 1,934 Microsoft.PowerShell_profile.ps1\r\n\r\n```\r\n\r\nAs @ThomasNieto [proposes below](https://github.com/PowerShell/PowerShell/issues/13590#issuecomment-688354542), a new _preference variable_ and _new switch_ for the `Format-*` cmdlets could allow opting into the old behavior. E.g.: `$PSThousandsGrouping` with values `$true` and `$false` (default `$true`), and switch\r\n`-ThousandsGrouping`.\r\n\r\n## Proposed technical implementation details (optional)\r\n\r\nHere's a quick _prototype_ that uses the ETS. It is _not_ the suggested implementation, for reasons of both performance and also changing the behavior of explicit `.ToString()` calls.\r\n\r\nA proper implementation would require modifying the formatting system itself.\r\n\r\n```powershell\r\n# Prototype:\r\n[int16], [int], [long], [double], [decimal], [bigint], [uint16], [uint], [uint64] | % {\r\n\r\n Update-TypeData -TypeName $_.FullName -MemberType ScriptMethod -MemberName ToString -Value { \r\n # Determine how many decimal places there are in the original representation.\r\n # Note: PowerShell's string interpolation uses the *invariant* culture, so '.'\r\n # can reliably be assumed to be the decimal mark.\r\n $numDecimalPlaces = (\"$this\" -replace '^[^.]+(?:.(.+))?', '$1').Length\r\n\r\n # Format with thousands grouping and the same number of decimal places.\r\n # Note: This will create a culture-sensitive representation\r\n # just like with the default output formatting.\r\n # CAVEAT:\r\n # To avoid a crash (from infinite recursion?), both .psobject.BaseObject \r\n # and the -f operator must be used.\r\n # ($this.psobject.BaseObject.ToString(\"...\") also crashes).\r\n \"{0:N$numDecimalPlaces}\" -f $this.psobject.BaseObject\r\n } -Force\r\n\r\n}\r\n```","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2020-09-06T19:43:54Z","url":"https://github.com/PowerShell/PowerShell/issues/13590"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:da247db2-627f-8605-92e6-bb9945313f03 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D492:2A7EC:12F9AE:1A9D16:6AFD4DB0 |
| html-safe-nonce | 130f5cbdd3bf472e92217f39cc2d14ddd6d053b92d9455469a8d2ff40afb84a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDkyOjJBN0VDOjEyRjlBRToxQTlEMTY6NkFGRDREQjAiLCJ2aXNpdG9yX2lkIjoiMzgyNjc2MjkzOTk0Mzk2NDA4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e47107006017bde853e23c9ee9d398b58cd32eb62ec71d5fad53c7052bafd29e |
| hovercard-subject-tag | issue:694503423 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/13590/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9efc2ae8f0275b7c5c18ab5c771d4e92aa53375f18c12fbbebb2dab21a0f16d3/PowerShell/PowerShell/issues/13590 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9efc2ae8f0275b7c5c18ab5c771d4e92aa53375f18c12fbbebb2dab21a0f16d3/PowerShell/PowerShell/issues/13590 |
| og:image:alt | Summary of the new feature/enhancement The output formatting system's purpose is to present data to the human reader. (As such - because the formatted output isn't meant for programmatic processing... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width