Home > database >  In PowerShell, how to format screen output for a decimal to display 2 places, like this example. I c
In PowerShell, how to format screen output for a decimal to display 2 places, like this example. I c

Time:03-20

$price = 22.5

write-host "The price is $"("{0:N2}" -f ($price))"!"

#NOTE: Prints out-> The price is $ 22.50 ! (Has an EXTRA SPACE after the $ & before the !)


I can do it this long way, but it is too much work: write-host "The price is $" -nonewline write-host ("{0:N2}" -f ($price)) -nonewline write-host "!"

CodePudding user response:

Has an EXTRA SPACE

The reason is that you're passing three arguments to output

  • Related