.NET Framework - Number formmating
Asked By Shay Levi
21-Sep-07 03:12 AM
I want to format a number with only one decimal place.
This is OK
PS > $number = 0.123
PS > [string]::format("{0:0.0}",$number)
0.1
If $number equels to 0.0 I want to return just 0.
Can it be done with .NET formattings (without if statment)?
Shay
http://scriptolog.blogspot.com
Siddaway
(1)
Formattings
(1)
Warranty
(1)
Equels
(1)
Ben Schwehn replied...
Shay,
use # instead of 0 e.g (43343.0).ToString("#.##"); returns just 43343
Ben
Ben Schwehn replied...
I meant 0.#, #.# will return an empty string for 0.0
Ben
Rich replied...
I think
[string]::format("{0:0.#}",$number)
should do it
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
Shay Levi replied...
Thanks, it does the trick :)
Shay
http://scriptolog.blogspot.com
PS>> $number = 0.123
PS>> [string]::format("{0:0.0}",$number)

and would be extremely grateful if someone can point out what I am missing - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk advantages - current conclusion is the .NET method is easier to understand and get working - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk seems much easier. Did you try creating a site with WMI at all? Thanks - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk protocol, ip addresses, ports etc Once I work that bit out its a winner - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk
for the help. Powershell Discussions System.windows.forms (1) LoadWithPartialName (1) RichS (1) Powergadgets (1) Siddaway (1) Powerpad (1) Windows.forms (1) Warranty (1) Nevermind, I finally got it. I had to add [void] [System.Reflection.Assembly]::LoadWithPartialName Sorry for the premature post. try $f = New-Object -Type System.Windows.Forms.Form - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk Thats odd because that assembly is loaded automatically on my machine - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk have PSCX loaded and PowerGadgets. Wouldn't be surprised if the latter loaded it - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk
on Vista SP1 - which is odd as I remember testing out PSjobs last year. - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk the Common files from IIS installed - you need the HTTP service to be available - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk C: \ > Could you to describe (or give link) all difference. About you debate with Richard Siddaway: WinRM service is WORK! Real problem is Runspace. For what reasons can be denied access CTP - you have the .NET 3.0 Windows Communication Foundation HTTP activation feature loaded - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk run the configure-wsman.ps1 script and that the HTTP SSL service is running - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http
your CreateTabletest.sql if you have multiple SAQL batches it may be getting confused - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk some execution type info. I'll test it tonight and get back to you - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk it didn't work with get-content. Need to have a think about that - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk the way get-content reads the file contents. Always soemthing new to dig into ;-) - - Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk
the following? Thanks. Powershell Discussions Windows 2008 Server (1) PowerGUI (1) RichS (1) Poshoholic (1) Siddaway (1) Shay (1) Windowsserver2008 (1) Warranty (1) Where did you read that? Can you provide a link? I don't believe before. As far as I'm aware Server Manager doesn't work like that - - Richard Siddaway All scripts are supplied "as is" and with no warranty PowerShell MVP Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk list but we cut it and didn't update the documentation" as kirk said - - Richard Siddaway All scripts are supplied "as is" and with no warranty PowerShell MVP Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk Thanks all ! The web page will be shortly updated to remove the incorrect information - - Richard Siddaway All scripts are supplied "as is" and with no warranty PowerShell MVP Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk