Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ private void setNewHostResponseBase(HostJoinVO host, EnumSet<HostDetails> detail
hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning));
hostResponse.setMemoryAllocated(mem);
hostResponse.setMemoryAllocatedBytes(mem);
String memoryAllocatedPercentage = decimalFormat.format((float) mem / memWithOverprovisioning * 100.0f) +"%";
hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage);
hostResponse.setMemoryAllocatedPercentage(calculateResourceAllocatedPercentage(mem, memWithOverprovisioning));

String hostTags = host.getTag();
hostResponse.setHostTags(hostTags);
Expand Down Expand Up @@ -401,6 +400,9 @@ public List<HostJoinVO> findByClusterId(Long clusterId, Host.Type type) {
}

private String calculateResourceAllocatedPercentage(float resource, float resourceWithOverProvision) {
if (resource == 0 || resourceWithOverProvision == 0) {
return "0.00%";
}
DecimalFormat decimalFormat = new DecimalFormat("#.##");
return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%";
Copy link

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast to (float) is unnecessary since the parameters are already declared as float. This redundant cast reduces code readability.

Suggested change
return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%";
return decimalFormat.format((resource / resourceWithOverProvision * 100.0f)) + "%";

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a separate PR/change as not touched here

}
Expand Down
Loading