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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting %

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
whats the best way to find out what % 158,189 is out of 632,756? rounded to the nearest tenth?

thanks
 
632756/158189 = 4
100/4 = 25
formatnumber(25,2) = 25.00 %

so um, basically let me try another example , something that'll show a bunch of percentages.

128/13 = 9.84615384615384615384615384615385
100/9.84615384615384615384615384615385 = 10.1562500000000000000000000000009

formatnumber(10.1562500000000000000000000000009, 2)
= 10.15 % Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
or....

you can do this

formatnumber((lowernumber/highernumber)*100, 2) Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
KB - won't using FormatNumber truncate not round and to the nearest tenth percent would be 1 decimal place.

Savok - Round(FormatPercentage(158189/632576),1) will do the division and automatically multiply by 100 and the ",1" will round to the nearest tenth.

HTH,
JC
 
I don't believe the round function works as expected when the argument is something.5 . If you want to consistently round, use your own algorithm.
 
petermeachem,
Yes, you are correct. The round algorithm uses a "financial Rounding" method. In VB, you will get this . . .

Code:
Round(1.5) = 2
Round(2.5) = 2
Round(3.5) = 4
Round(4.5) = 4


Essentially. when rounding odd number with 1/2 the number is rounded up and even numbers are rounded down. A more "classical" approach to rounding would be to say this . . .

SomeNumber = the number to be rounded.
decimalplace = the decimal position to round to (base 0)
Code:
SomeNumber = 2.5
SomeNumber = Int(SomeNumber * (10^decimalplace) + .5)/(10^decimalplace)

- Jeff Marler B-)
 
Yes, you have to be careful with tax values. In the UK we always round up VAT (Value Added Tax) to avoid the taxman getting all stressy.
 
petermeachem,
Taxman . . . grrrrrrrrrr - Jeff Marler B-)
 
petermeachem,
Taxman . . . grrrrrrrrrr >:-< - Jeff Marler B-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top