Saturday, 15 May 2010

powershell - Formatting an integer x.xxxxx as xx.xxx -



powershell - Formatting an integer x.xxxxx as xx.xxx -

i have number $int

$int = 9.5587452369

i want number in format xx.xxx tried :

$int = "{0:n3}" -f ($int) $int = "{0:d2}" -f ($int)

or

$int = "{0:d2}" -f ("{0:n3}" -f ($int))

but doesn't work ideas ?

use tostring() method specified format.

ps > $int = 9.5587452369 ps > $int.tostring("00.000") 09,559

or

ps > "{0:00.000}" -f $int 09,559

read more @ msdn - custom numeric format strings

powershell formatting

No comments:

Post a Comment