Open sunnykgupta opened 8 years ago
This error is expected. mmol/l
and mg/dl
are not dimensionally compatible (the kind of the former is a molar concentration and the latter is density), so they cannot be converted to each other.
In specific domain like yours, it could be convertible because some units are assimilated to others. In your case, mol
is considered as a mass (the mass of 1 mole of glucose).
I don't know yet how those very domain-specific cases could be handled.
Thanks. I'll implement my functions separately. 😃
In the case of mmol/l to mg/dl conversion, the missing step that's assumed is multiplying by the molecular weight of glucose g/mol.
Does js-quantities handle units during multiplication and division?
If so, would this work to do this conversion?
'Qty('
Yes it should work as js-quantities handles units multiplication and division (but it seems to be a small rounding error here, I will try to track it down).
mmol/l = mg/dl / 18 mg/dl = 18 × mmol/l
Trying to make a medical calculator with js-quantities. But can't seem to convert between the two frequently used units to measure blood sugar.
Anything I'm missing?
I tried -
Qty.swiftConverter('mmol/l', 'mg/dl');
Results in :
"QtyError", "Incompatible units"
Thanks in advance.