[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 519

# PerformanceCounter.NextValue()

The Performance Counter returns a value on the Category "Network interface" on the counter Current Bandwidth it returns 1E+08 when i execute the PerformanceCounter.Nextvalue() method.

How do i calculate this to be an integer that i can understand?
0
databoks
• 4
• 3
1 Solution

Software EngineerCommented:
This method returns a float. you can cast it:
float myFloatValue = 10.3F;
int myIntValue = (int)myFloatValue;
0

Software EngineerCommented:
Just to complement my previous comment.
Casting can be used when you are sure the float value will be within the integer range.
You should do the conversion like:
private int FloatToInt(float value)
{
if (value > int.MinValue || value <= int.MaxValue)
return (int)value;
else
return int.MinValue;//Do something to deal with this error
}
0

Author Commented:
What is the formel to calculate it to and int or a long?
0

Software EngineerCommented:
It depends how big you expect the float number to be. If your number is less than int.MaxValue then int is enough ,else use "long"
For long is very easy just replace "int" in my previous code with long.
An alternative is to divide your float number by 1000 or 1000000 if you know you have to deal with big numbers only and it does not affect the order of magnitude that you are trying to monitor
0

Software EngineerCommented:
Can databoks explain how his/her fixed solution is different from mine?
0

Author Commented:
I was developing this but the project has been outsourced so i don't have to spend time to this.

Therefor i don't know if you solution has worked - and i don't have time to test it.

0

Author Commented:
how can i know if the posted question is correct if i haven't testet it?

However i don't want to spend time on this anymore.
0

## Featured Post

• 4
• 3
Tackle projects and never again get stuck behind a technical roadblock.