0

I have an object that has some cpu stats. The problem is that those that's are in type long (i think)

How can I convert this to usefull values like float and int?

I tried to cast it but I got

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Float

enter image description here

float value = (float) Docker.getStatistics("ENVX").getCpuStats().get("system_cpu_usage");
sadas
  • 47
  • 1
  • 4

1 Answers1

3

I don't really understand why would you want to convert a 64-bit value to a 32-bit, risking to lose precision, but you can try with:

Long cpu = Docker.getStatistics("ENVX").getCpuStats().get("system_cpu_usage");
Float f = Float.valueOf(cpu.toString());
Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147