Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Custom format numeric values

Reply
 
Old 10-04-2008   #1 (permalink)
Robertico


 
 

Custom format numeric values

Hi,

How to make a custom format for my numeric values.
I need to format respectively 5197213 and 459832 to 51.97213 and 4.59832
(dot - 5 decimal)

Regards,

Robertico



My System SpecsSystem Spec
Old 10-04-2008   #2 (permalink)
RichS [MVP]


 
 

RE: Custom format numeric values

Is this just for display or do you want to keep it as a numeric format with a
fixed 5 decimal places??

if just for display try

"{0:F5} {1:F5}" -f (5197213/100000), (459832/100000)

--
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.org.uk


"Robertico" wrote:
Quote:

> Hi,
>
> How to make a custom format for my numeric values.
> I need to format respectively 5197213 and 459832 to 51.97213 and 4.59832
> (dot - 5 decimal)
>
> Regards,
>
> Robertico
>
>
>
My System SpecsSystem Spec
Old 10-04-2008   #3 (permalink)
Shay Levy [MVP]


 
 

Re: Custom format numeric values


You can format the numbers with the zero placeholder format specifier:


PS > "{0:0\.00000}" -f 5197213
51.97213

PS > "{0:0\.00000}" -f 459832
4.59832



---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar



R> Hi,
R>
R> How to make a custom format for my numeric values.
R> I need to format respectively 5197213 and 459832 to 51.97213 and
R> 4.59832
R> (dot - 5 decimal)
R> Regards,
R>
R> Robertico
R>


My System SpecsSystem Spec
Old 10-05-2008   #4 (permalink)
Robertico


 
 

Re: Custom format numeric values

Shay,

"{0:0\.00000}" ... thats the trick.... i forgot the backslash before the
decimal dot.
(the output is saved as text file !)

Thanks and regards,

Robertico

"Shay Levy [MVP]" <no@xxxxxx> wrote in message
news:89228ed249ad38caf4abbf7c4ad4@xxxxxx
Quote:

>
> You can format the numbers with the zero placeholder format specifier:
>
>
> PS > "{0:0\.00000}" -f 5197213
> 51.97213
>
> PS > "{0:0\.00000}" -f 459832
> 4.59832
>
>
>
> ---
> Shay Levy
> Windows PowerShell MVP
> http://blogs.microsoft.co.il/blogs/ScriptFanatic
> PowerShell Toolbar: http://tinyurl.com/PSToolbar
>
>
>
> R> Hi,
> R> R> How to make a custom format for my numeric values.
> R> I need to format respectively 5197213 and 459832 to 51.97213 and
> R> 4.59832
> R> (dot - 5 decimal)
> R> Regards,
> R> R> Robertico
> R>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Custom Now Playing-format in Messenger 2009? Live Messenger
-f format Format-Table Format-List against Select PowerShell
Need help to split a string into text and numeric values !! VB Script
Can I create a Default output format for custom objects PowerShell
[Ann] Format-Graph custom CmdLet to display graphics within PowerShell PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46