![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
bytes = int(bytes/1024)
is there any funcion similar to int for abs in ksh |
|||
| Google The UNIX and Linux Forums |