Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts

    print numeric values with different digits

    I am trying to print 5 values in each line. The problem is that each of these five columns could have values with different digits in different rows. Is there a way I can set them up, so that they all have a same digits?

    For example, for '2', and '56789', is there a way I can show them as ' 2 ', and '56789'?

    Thanks.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by camaross View Post
    I am trying to print 5 values in each line. The problem is that each of these five columns could have values with different digits in different rows. Is there a way I can set them up, so that they all have a same digits?

    For example, for '2', and '56789', is there a way I can show them as ' 2 ', and '56789'?

    Thanks.
    there is a difference between how it look and what it is and depend of the tool you use too look at this.
    Browser for example ignore spaces and you can use css to format how it look.
    if you want only to put some spaces or 0 to have any number to same length you can use printf for output or sprintf to build a 'string' and use it later.

    Code:
    my $right_padded_num = sprintf "%5d", 2;
    see man perlfunc

    best regards

  • Users who have thanked oesxyl for this post:

    camaross (04-14-2011)

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    68
    Thanks
    0
    Thanked 28 Times in 28 Posts
    perldoc sprintf

    Code:
    my $left_padded_num = sprintf "% 5d", 2;

  • Users who have thanked miller for this post:

    camaross (04-14-2011)

  • #4
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thank you very much!

    Quote Originally Posted by miller View Post
    perldoc sprintf

    Code:
    my $left_padded_num = sprintf "% 5d", 2;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •