The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




Thread: absolute value
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 08-26-2008
sad_angle's Avatar
sad_angle sad_angle is offline
Registered User
  
 

Join Date: Jun 2001
Location: Madison, WI
Posts: 75
Rounding floating point numbers?

Try Perl function "sprintf".

I'd say

#!/usr/bin/perl -w
# This will round the value of Y to two decimal points, using ".2f"
$Y=14.875;
$roundedY= sprintf "%.2f", $Y;
print "$roundedY \n";
exit;

For more details look at sprintf - formatted print into a string

The same is in C and Korn in the man pages. I hope this helps.

Good luck