1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const WeightToMg = (value, unit) => {
if (unit == 'g') {
return value * 1000;
} if (unit == 'kg') {
return value * 1000000;
}
}
const MgToWeight = (value, unit, display) => {
if (typeof display === 'undefined') display = false;
if (unit == 'g') {
return Math.round(100 * value / 1000.0) / 100;
} if (unit == 'kg') {
return Math.round(100 * value / 1000000.0, 2) / 100;
}
}
export default {
WeightToMg,
MgToWeight,
};