Aligning 2d array of numbers

Discussion in 'Perl' started by Dave Bazell, Jul 31, 2003.

  1. Dave Bazell

    Dave Bazell Guest

    I have a large array of numbers, say 10,000 rows by 8 columns. The numbers
    are mostly floating point but some integers. I want to align each column by
    the decimal point or right justify the integers. Is there an easy (read
    obvious) way to do this? My current code reads everything in as a string
    and does a split to put each number in an array. So I have an internal
    represenation of what I want, I just have to output it correctly.

    The other issue is I have different input arrays, different precision
    numbers, and different numbers of columns, so I have to do the formatting on
    the fly.

    An example is:

    2.37 2.99 .22 -1.25 648829 1 1 2.5 2
    3.1 1.22 2.78 10.34 23221 1 2 19.2 3

    and I want thse to come out aligne on the decimal point in each column. For
    a given data file, the floats and integers always occur in the same column.

    Thanks,

    Dave
     
    Dave Bazell, Jul 31, 2003
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Todd Gardner

    hex array to array of 16 bit numbers?

    Todd Gardner, Dec 25, 2003, in forum: Python
    Replies:
    4
    Views:
    472
    Francis Avila
    Dec 27, 2003
  2. Subra
    Replies:
    25
    Views:
    1,564
    user923005
    Mar 8, 2007
  3. Andrew Tatum

    Fibonacci Numbers and Lucas Numbers

    Andrew Tatum, May 26, 2007, in forum: C++
    Replies:
    6
    Views:
    815
    Howard
    May 27, 2007
  4. Lance Hoffmeyer
    Replies:
    2
    Views:
    736
    Lance Hoffmeyer
    Jul 26, 2007
  5. jko170
    Replies:
    9
    Views:
    342
    jko170
    Jan 21, 2009
  6. GIMME
    Replies:
    5
    Views:
    412
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
  7. D'Anne Asquith

    Numbers not acting like numbers

    D'Anne Asquith, Oct 1, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    238
    Heinrich Mislik
    Oct 2, 2003
  8. one man army

    Numbers to strings to numbers again

    one man army, Dec 28, 2005, in forum: Javascript
    Replies:
    6
    Views:
    313
    one man army
    Dec 30, 2005
Loading...