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



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 07:26 AM
absolute path Kirichiko UNIX for Dummies Questions & Answers 2 10-03-2007 06:30 AM
absolute path filedeliver High Level Programming 4 06-05-2007 05:18 PM
Getting absolute value ksh icyhot UNIX for Dummies Questions & Answers 3 03-30-2006 06:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-26-2008
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 92
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
  #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
  #3 (permalink)  
Old 08-26-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
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)'
  #4 (permalink)  
Old 08-26-2008
dr46014 dr46014 is offline
Registered User
  
 

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

is there any funcion similar to int for abs in ksh
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0