Skip to content

Commit

Permalink
CS1-28: Fix percent value scale
Browse files Browse the repository at this point in the history
  • Loading branch information
andersio committed Nov 14, 2023
1 parent 465d0a9 commit cefe2f9
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ extension QuantitySample {
guard let value = sample as? HKQuantitySample else {
return nil
}


let unit = sample.sampleType.toHealthKitUnits
var doubleValue = value.quantity.doubleValue(for: unit)

if unit == HKUnit.percent() {
// Vital uses [0, 100[ instead of [0, 1[, so we need to scale up the percentage.
doubleValue = doubleValue * 100
}

self.init(
id: value.uuid.uuidString,
value: value.quantity.doubleValue(for: sample.sampleType.toHealthKitUnits),
Expand Down

0 comments on commit cefe2f9

Please sign in to comment.