• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

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

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
tushar7
Asked:
tushar7
  • 3
1 Solution
 
zlobchoCommented:
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
 
zlobchoCommented:
or
$ostring=sprintf("%10s",$istring);
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now