Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding question

Status
Not open for further replies.

Wrathchild

Technical User
Aug 24, 2001
303
US
Thanks to this board I was able to figure out how to us bc effectively and then drop off the excessive numbers since I want the format 000.00

My question is right now I'm just cutting off the numbers to the right of the 2nd decimal position, so the hundreths aren't alwasy correct due to lack of rounding. How can I incorporate rounding?

Code:
PERCENT=`printf "%s\n" "scale = 5; ($COUNT5 / $COUNT * 100)" | bc`
PERCENT=${PERCENT%???}
 
What about this ?
$COUNT5 / $COUNT * 100 [/!]+ 0.05[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ok, what am I missing?
Syntax error:
Code:
PERCENT=`printf "%s\n" "scale = 5; ($COUNT5 / $COUNT * 100 [/!]+0.05[/!]) " | bc`
 
Code:
PERCENT=`printf "%s\n" "scale = 5; ($COUNT5 * 100 / $COUNT + 0.005) " | bc`

Jean-Pierre.
 
Sorry for the typo and the wrong TGML :~/
$COUNT5 / $COUNT * 100 [!]+ 0.005[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
no problem PHV, you're due one in a million postings :)

This doesn't seem to be rounding, unless I'm just not understanding what's going on:
17235/17303 = .99607 so I would like to see 99.61%
 
I meant this:
COUNT5=17235;COUNT=17303
PERCENT=`printf "%s\n" "scale=5; $COUNT5/$COUNT*100+0.005" | bc`
PERCENT=${PERCENT%???}
echo $PERCENT

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
nevermind...I applied it to the wrong line of code
 
Thanks guys, that did it. I wasn't sure if there was a "round" function or not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top