Browse Source

Format bolus amount on watch according to bolusIncrement

Mike Plante 1 year ago
parent
commit
2448b7be9c
1 changed files with 4 additions and 2 deletions
  1. 4 2
      Trio Watch App Extension/Views/BolusInputView.swift

+ 4 - 2
Trio Watch App Extension/Views/BolusInputView.swift

@@ -74,8 +74,10 @@ struct BolusInputView: View {
                         Spacer()
 
                         // Display the current carb amount
-                        // TODO: format this properly using state.bolusIncrement
-                        Text(String(format: "%.2f U", bolusAmount * Double(truncating: state.bolusIncrement as NSNumber)))
+                        let bolusIncrement = Double(truncating: state.bolusIncrement as NSNumber)
+                        let adjustedBolusAmount = floor(bolusAmount / bolusIncrement) * bolusIncrement
+
+                        Text(String(format: "%.2f U", adjustedBolusAmount))
                             .fontWeight(.bold)
                             .font(.system(.title2, design: .rounded))
                             .foregroundColor(bolusAmount > 0.0 && bolusAmount >= effectiveBolusLimit ? .loopRed : .primary)