1

I have integer values: 3 60 150 1500 and float values 1.23354, 1.234, 1.234567...
I calculate the number of digits of the biggest integer:

    $nInt = [System.Math]::Ceiling([math]::log10($maxInt))
    # nInt = 4

and in another way the biggest number of dec. behind the decimal point of the float-variable: $nDec = 6

  1. How can I format a print out that all integer do have the same string-length with leading spaces?

    |1500
    | 500
    |  60
    |   3
    
  2. And all float with the same string-length as well?

       1.234567|
       1.23354 |
       1.234   |
    

The | is just to mark my 'point of measure'.

Of course I have to choose a character-set where all characters do have the same pixex-size.

I am thinking of formatting by "{0:n}" or $int.ToString(""), but I can't see how to use this.

1 Answer 1

2

Try PadLeft or PadRight. For example, for your integers:

$maxInt.ToString().PadLeft($nInt.ToString().Length, ' ')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.