Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[VB.NET]Get Percent Value

Description:

Calculates the Percentvalue of a given value depending on a maximum value.

Code
Public Function Percent(ByVal CurrVal As Long, ByVal MaxVal As Long) As Integer
    Return Int(CurrVal / MaxVal * 100 + 0.5)
End Function

originally posted on dotnet-snippets.com

[img]http://i685.photobucket.com/albums/vv215/blackpearl4/THANKS.gif[/img]
If You Like this tutorial, please check out my other tutorials by clicking ==> H3R3
PHP & .NET Contributor.
Er....why is it + 0.5 ?
(May 3, 2010 10:10 PM)6e756c6c Wrote:  Er....why is it + 0.5 ?

I have no idea but I think it is wrong because the returned value will be 0.5 too big
Use a double not integer to be precise..
Code
CDbl(CurrVal / MaxVal * 100)

And have your inputs doubles too.
[Image: Xtddh8V.png]
This code should be...

Code
Public Function Percent(ByVal current As Double, ByVal maximum As Double) As Integer
        Return current / maximum * 100
    End Function
all fixed to your preference
PHP & .NET Contributor.
There should not be the +0.5 ... anyway in math no.
@ Learn4Life....im sorry i can't understand your question.
PHP & .NET Contributor.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by SIM-1895121Oct 31, 2017 10:19 AM 9 311 Oct 31, 2017 10:19 AM
Last Post: 0xDEAD10CC
[C] by вonsaiDec 4, 2014 11:56 AM 14 480 Dec 4, 2014 11:56 AM
Last Post: Mouse❤️
[C] by RHurford89Apr 24, 2013 10:35 PM 2 120 Apr 24, 2013 10:35 PM
Last Post: RHurford89