Просмотр исходного кода

Use 1 maximumFractionDigit when mmol/l

Jon Mårtensson 2 лет назад
Родитель
Сommit
5849cee4ea
1 измененных файлов с 12 добавлено и 3 удалено
  1. 12 3
      FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

+ 12 - 3
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -20,6 +20,15 @@ extension Bolus {
             return formatter
             return formatter
         }
         }
 
 
+        private var gluoseFormatter: NumberFormatter {
+            let formatter = NumberFormatter()
+            formatter.numberStyle = .decimal
+            if state.units == .mmolL {
+                formatter.maximumFractionDigits = 1
+            } else { formatter.maximumFractionDigits = 0 }
+            return formatter
+        }
+
         private var fractionDigits: Int {
         private var fractionDigits: Int {
             if state.units == .mmolL {
             if state.units == .mmolL {
                 return 1
                 return 1
@@ -36,20 +45,20 @@ extension Bolus {
                             value: Binding(
                             value: Binding(
                                 get: {
                                 get: {
                                     if state.units == .mmolL {
                                     if state.units == .mmolL {
-                                        return state.currentBG * 0.0555
+                                        return state.currentBG.asMmolL
                                     } else {
                                     } else {
                                         return state.currentBG
                                         return state.currentBG
                                     }
                                     }
                                 },
                                 },
                                 set: { newValue in
                                 set: { newValue in
                                     if state.units == .mmolL {
                                     if state.units == .mmolL {
-                                        state.currentBG = newValue * 0.0555
+                                        state.currentBG = newValue.asMmolL
                                     } else {
                                     } else {
                                         state.currentBG = newValue
                                         state.currentBG = newValue
                                     }
                                     }
                                 }
                                 }
                             ),
                             ),
-                            formatter: formatter,
+                            formatter: gluoseFormatter,
                             autofocus: false,
                             autofocus: false,
                             cleanInput: true
                             cleanInput: true
                         )
                         )