Copilot commented on code in PR #11302:
URL: https://github.com/apache/cloudstack/pull/11302#discussion_r2235023387


##########
server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java:
##########
@@ -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)) + "%";

Review Comment:
   The cast to (float) is unnecessary since the parameters are already declared 
as float. This redundant cast reduces code readability.
   ```suggestion
           return decimalFormat.format((resource / resourceWithOverProvision * 
100.0f)) + "%";
   ```



##########
server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java:
##########
@@ -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) {

Review Comment:
   The condition should check for resourceWithOverProvision == 0 only, since 
dividing by zero resource value is valid and would result in 0%. The current 
logic incorrectly returns 0% when resource is 0 but resourceWithOverProvision 
is non-zero, which should actually calculate as 0% anyway but through the 
normal formula.
   ```suggestion
           if (resourceWithOverProvision == 0) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to