Unix/Linux Go Back    

Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

perl: simple question on string append

Shell Programming and Scripting

Closed Linux or Unix Question    
Thread Tools Search this Thread Display Modes
Old Unix and Linux 05-14-2007
the_learner the_learner is offline
Registered User
Join Date: Apr 2007
Last Activity: 21 October 2013, 8:14 PM EDT
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
perl: simple question on string append

I want to append a decimal number to a string. But I want to restrict the number to only 2 decimal points

for e.g:

my $output = "\n The number is = ";
my $number = 2.3333333;

$output = $output . $number;

But I want the $output as: "The number is = 2.33"; and not 2.3333333

(I do not want to print $output right now.. I just want it to have the number with only 2 decimal points)

can anyone please helpout..

Thanks !!!!!!!!!!!!
Old Unix and Linux 05-14-2007
jim mcnamara jim mcnamara is offline Forum Staff  
Join Date: Feb 2004
Last Activity: 1 December 2015, 9:33 AM EST
Location: NM
Posts: 10,597
Thanks: 373
Thanked 895 Times in 831 Posts

$result = sprintf("%.2f", $number);

Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl script to look for a string in a file and append few lines if the match is found arunkumarmc Programming 1 03-04-2011 06:05 PM
how to append a string to next line in perl tprayush Shell Programming and Scripting 2 04-09-2010 04:58 PM
Simple perl question streetfighter2 Shell Programming and Scripting 3 12-22-2009 09:33 PM
PERL: simple comparing arrays question hcclnoodles Shell Programming and Scripting 5 09-07-2009 05:43 PM
simple question on string concat the_learner Programming 2 08-24-2007 12:09 AM

All times are GMT -4. The time now is 11:20 PM.