Bird
0
0

Which command correctly formats the output with product left-aligned in 15 spaces and price right-aligned with 2 decimals in 8 spaces?

hard📝 Application Q8 of 15
PowerShell - String Operations
You want to format a table of product names and prices aligned in columns using -f. Which command correctly formats the output with product left-aligned in 15 spaces and price right-aligned with 2 decimals in 8 spaces?
$product = "Book"
$price = 12.5
?
A"{0,15} {1,-8:N2}" -f $product, $price
B"{0,-15} {1,8:N2}" -f $product, $price
C"{0,-15} {1,-8:N2}" -f $product, $price
D"{0,15} {1,8:N2}" -f $product, $price
Step-by-Step Solution
Solution:
  1. Step 1: Understand alignment requirements

    Product should be left-aligned in 15 spaces, so {0,-15} is correct.
  2. Step 2: Format price right-aligned with 2 decimals in 8 spaces

    {1,8:N2} formats price right-aligned with 2 decimals.
  3. Final Answer:

    "{0,-15} {1,8:N2}" -f $product, $price -> Option B
  4. Quick Check:

    Left-align product, right-align price with decimals = B [OK]
Quick Trick: Use negative width for left-align, positive for right-align [OK]
Common Mistakes:
  • Swapping alignment signs
  • Missing numeric format for price
  • Using wrong width values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes