Switch from casting to_f to using fdiv dividing floats

This commit updates places where previously we were casting both terms
in a float division into floats in order to ensure that float division
occurs to use the `fdiv` method, which will always do float division and
is available on both `Floats` and `Integers` because they are
both `Numeric`.
This commit is contained in:
Brandon High 2020-03-05 16:11:42 -08:00
parent 532ca96131
commit 367565a3ee
No known key found for this signature in database
GPG key ID: 270079C784FCAFDE
2 changed files with 3 additions and 3 deletions

View file

@ -216,7 +216,7 @@ module Vmpooler
capacity[:current] = get_total_across_pools_redis_scard(pools, 'vmpooler__ready__', backend)
if capacity[:total] > 0
capacity[:percent] = ((capacity[:current].to_f / capacity[:total].to_f) * 100.0).round(1)
capacity[:percent] = (capacity[:current].fdiv(capacity[:total]) * 100.0).round(1)
end
capacity

View file

@ -759,7 +759,7 @@ module Vmpooler
return nil if cpu_usage.nil?
cpu_size = host.summary.hardware.cpuMhz * host.summary.hardware.numCpuCores
(cpu_usage.to_f / cpu_size.to_f) * 100
cpu_usage.fdiv(cpu_size) * 100
end
def memory_utilization_for(host)
@ -767,7 +767,7 @@ module Vmpooler
return nil if memory_usage.nil?
memory_size = host.summary.hardware.memorySize / 1024 / 1024
(memory_usage.to_f / memory_size.to_f) * 100
memory_usage.fdiv(memory_size) * 100
end
def get_average_cluster_utilization(hosts)