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
Rounding off the value of Floating point value damansingh Shell Programming and Scripting 7 05-21-2008 09:46 AM
Rounding off using BC. noodlesoup Shell Programming and Scripting 3 09-11-2006 12:38 AM
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 10:10 AM
SSH Problem auth problem budrito UNIX for Advanced & Expert Users 1 03-17-2004 10:12 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-17-2007
shash shash is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
Rounding problem

Hi,

Can any one help me in finding a solution for rounding off to 2 decimal places.

I am using the following code:

VAR1=.01292105263157894736
VAR2=`echo "scale=2; $VAR1 * 100" | bc -l`

The result I 'm getting is
1.29210526315789473600

But I need the output as 1.29

Thanks
Shash
  #2 (permalink)  
Old 01-17-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try awk:

$ echo .02199 | awk '{printf "%.2f \n", $1*100; }'
2.20
  #3 (permalink)  
Old 01-18-2007
shash shash is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
Thanks! This works perfectly.
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 11:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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