0

I am designing my own EOS dashboard in which I want to show the respective account's resources CPU, NET and RAM in Percentage as they are in the attached picture (from https://local.bloks.io/):

enter image description here

when I get account information, I am getting values max cpu_limit, used cpu_limit, available cpu_limit, max net_limit, used net_limit, available net_limit, ram_quota and ram_usage. I tried to calculate percentage same for all using:

var cpuProgress = ((double)cpuUsed / cpuMax) * 100.0;
var cpuPercentage = cpuProgress.ToString("#0.##%", CultureInfo.InvariantCulture);

But I guess I am mistaken. Please help how to calculate these three resources in percentage?

1 Answer 1

1

The values you are using should be correct for CPU and NET. max for the max the user has and used for what they currently have consumed. There should also be available which is how much they have remaining. used + available = max.

For RAM however it would be ram_quota and ram_usage.

So I would use something like this, changing the variable names to whatever you are using.

parseFloat((cpu_limit.used / cpu_limit.max) * 100);

Be sure that however you are assigning these variables when you retrieve the account information that the correct values are being stored.

2
  • The values type is long. Cannot use parseFloat.
    – Varsh
    Apr 8, 2021 at 2:18
  • 1
    It's parsing the result of the division, not the values, example: (56383/3408838) * 100 = 1.65402403986 You can then add .toFixed(2) on the end to force it to two decimal places. I am using this very method in a React app. Apr 9, 2021 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.