Operating System - HP-UX
1828038 Members
1935 Online
109973 Solutions
New Discussion

PERL question: How to format floating point number

 
SOLVED
Go to solution
mooi-kuan
Advisor

PERL question: How to format floating point number

Hi Perl experts:
I have an array consists of floating point numbers like this:
74.2021276595745
3.98936170212766
4.2553191489361
1.06382978723404
7.97872340425532
8.51063829787234

I use printf ("%3.2f", $my_array) to round up the number. However, the output is align to the left side. How can I make it align to right ?


Thanks for you help.
mk
2 REPLIES 2
Steven Sim Kok Leong
Honored Contributor

Re: PERL question: How to format floating point number

Hi,

Have you tried using the perl format function? You can either execute perldoc -f format or simply man perlform for more information. There are examples in perlform that performs right-justification.

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
Philip Chan_1
Respected Contributor
Solution

Re: PERL question: How to format floating point number

Try the following printf statement instead,

printf ("%10.2f", $my_array);

~Philip