Title: [PSCustomObject] How to format the output of non-integer numbers? · Issue #19107 · PowerShell/PowerShell · GitHub
Open Graph Title: [PSCustomObject] How to format the output of non-integer numbers? · Issue #19107 · PowerShell/PowerShell
X Title: [PSCustomObject] How to format the output of non-integer numbers? · Issue #19107 · PowerShell/PowerShell
Description: PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
Open Graph Description: PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
X Description: PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
Opengraph URL: https://github.com/PowerShell/PowerShell
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[PSCustomObject] How to format the output of non-integer numbers?","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nI already opened a similar issue, then I did not receive a reasonable answer, I decided to wait until the new release, but nothing has changed.\r\n\r\nIf you use the table format, then trailing zeros are added to the non-integer numeric value:\r\n```powershell\r\n[pscustomobject] @{ dollar = 1.95; monat = 20.01 }\r\n\r\ndollar monat\r\n------ -----\r\n 1,950 20,010\r\n ```\r\nIf I cast these values to a string type, then I will have to format the alignment in the columns of the table:\r\n```powershell\r\n[pscustomobject] @{ dollar = 1.95; monat = 20.01 }\r\n| Format-Table @{lab='dollar'; exp={$_.dollar.ToString()}; a='right'},\r\n @{lab='monat'; exp={$_.monat.ToString()}; a='right'}\r\n\r\n\r\ndollar monat\r\n------ -----\r\n 1,95 20,01\r\n```\r\nor\r\n```powershell\r\n[pscustomobject] @{ dollar = [string] 1.95; monat = [string] 20.01 }\r\n| Format-Table @{lab='dollar'; exp={$_.dollar}; a='right'},\r\n @{lab='monat'; exp={$_.monat}; a='right'}\r\n```\r\nOr get this object as a list.\r\n\r\nBut the situation is such that the script outputs an object with more than thirty values and six properties.\r\nThus, the complete list will be 30 * 6 + 30 separators = 210 lines. The only possible option is a table.\r\nBut I will not format the output of the script directly in the console.\r\n\r\nThe variant with alignment right during the formation of the object is also not suitable, because there will be indents when viewed as a list.\r\n\r\n```powershell\r\n[pscustomobject] @{ dollar = '{0,6}' -f 1.95; monat = '{0,5}' -f 20.01; weather = 'clear' }\r\n| Format-List\r\n\r\n\r\ndollar : 1,95\r\nmonat : 20,01\r\nweather : clear\r\n```\r\nAdvise what to do, in Windows it is tolerable, there is only one zero added, up to hundredths, and in Linux two zeros, up to thousandths.\r\n\r\n\r\n### Expected behavior\r\n\r\n```console\r\nTable view of PsCustomObject should not add trailing zeroes, should return value of non-integer numeric as is.\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n```console\r\nPSCustomObject adds trailing zeroes to table format.\r\n```\r\n\r\n\r\n### Error details\r\n\r\n```console\r\nNo Errors\r\n```\r\n\r\n\r\n### Environment data\r\n\r\n```powershell\r\nName Value\r\n---- -----\r\nPSVersion 7.4.0-preview.1\r\nPSEdition Core\r\nGitCommitId 7.4.0-preview.1\r\nOS Linux 6.1.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 01 Feb 2023 17:07:39 +0000\r\nPlatform Unix\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n\r\n\r\n### Visuals\r\n\r\nHorror","author":{"url":"https://github.com/237dmitry","@type":"Person","name":"237dmitry"},"datePublished":"2023-02-04T23:31:45Z","url":"https://github.com/PowerShell/PowerShell/issues/19107"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:a04695cc-0b11-f296-f26b-42f61712db60 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 858E:B6856:478946:64B347:6AFDB876 |
| html-safe-nonce | d0f2806bda1c7dd2bad25a7fdd126e44b28073cdc9ccddf9d76d01ca99bf26ad |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NThFOkI2ODU2OjQ3ODk0Njo2NEIzNDc6NkFGREI4NzYiLCJ2aXNpdG9yX2lkIjoiNjMxMzEzNDM3Njc3NTE3MDE2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4be16bf853710ef35265b76f181dd126dcf7ad0b8ba89698ade17048cb7acf8e |
| hovercard-subject-tag | repository:49609581 |
| 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/PowerShell/PowerShell/issues/19107 |
| twitter:image | https://repository-images.githubusercontent.com/49609581/aad0ad80-cdec-11ea-8248-a37bc0571bfd |
| twitter:card | summary_large_image |
| og:image | https://repository-images.githubusercontent.com/49609581/aad0ad80-cdec-11ea-8248-a37bc0571bfd |
| og:image:alt | PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub. |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8309f07eb60a4237a657068c83d0bb57be4c7e02937f5e9933126f4bd596aac4 |
| turbo-cache-control | no-cache |
| 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 | 2f7154d847f1ddc5baa83b109a3e1d924605e2a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width