Solved

Perl Question: Making a number string from left aligned to right aligned

Posted on 2009-07-06
3
151 Views
Last Modified: 2012-05-07
I have a number string which is of length 10. The number is left aligned and I want to make it right aligned.
For e.g.
Input string = 12345.99  
Expected result =   12345.99

Input String = "120.87    "
Expected Result = "    120.87"
0
Comment
Question by:tushar7
  • 3
3 Comments
 
LVL 6

Accepted Solution

by:
zlobcho earned 500 total points
ID: 24786497
Try this:
#!/usr/bin/perl
 

#Input string

$istring = "120.87    ";

#Expected Result

$ostring=sprintf("%10.2f",$istring);
 

print $istring;

print "\n";

print $ostring;

Open in new window

0
 
LVL 6

Expert Comment

by:zlobcho
ID: 24786554
or
$ostring=sprintf("%10s",$istring);
0
 
LVL 6

Expert Comment

by:zlobcho
ID: 24786600
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now