The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Absolute value placroix1 Shell Programming and Scripting 5 12-04-2007 04:26 AM
absolute path Kirichiko UNIX for Dummies Questions & Answers 2 10-03-2007 03:30 AM
absolute path filedeliver High Level Programming 4 06-05-2007 02:18 PM
Getting absolute value ksh icyhot UNIX for Dummies Questions & Answers 3 03-30-2006 03:05 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-25-2008
Registered User
 

Join Date: Jun 2007
Posts: 70
absolute value

is there any function in unix which will convert a integer to absolute value with a single decimal point.

suppose x=15232
y=x/1024=14.875

i want y to be 14.8

Similarly if y=6.29452 it should come as 6.3
Reply With Quote
Forum Sponsor
  #2  
Old 08-26-2008
sad_angle's Avatar
Registered User
 

Join Date: Jun 2001
Location: Madison, WI
Posts: 73
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
Reply With Quote
  #3  
Old 08-26-2008
Registered User
 

Join Date: Jun 2008
Location: Scotland
Posts: 121
For the absolute value (and one decimal place), you would also use Perl's abs function, e.g.:
Code:
perl -e 'printf "%.1f\n", abs(15232/1024)'
Reply With Quote
  #4  
Old 08-26-2008
Registered User
 

Join Date: Jun 2007
Posts: 70
bytes = int(bytes/1024)

is there any funcion similar to int for abs in ksh
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0