Skip to content

Commit

Permalink
update convertValueNew function to allow conversion from kW to W and …
Browse files Browse the repository at this point in the history
…MW to kW when values < 1
  • Loading branch information
slipx06 committed Mar 24, 2024
1 parent 88458f7 commit 03b1da1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export class Utils {
return `${Math.round(numberValue)} ${unit}`;
};

if (unit === UnitOfPower.KILO_WATT && Math.abs(numberValue) < 1) {
return `${Math.round(numberValue * 1000)} W`;
}

if (unit === UnitOfPower.MEGA_WATT && Math.abs(numberValue) < 1) {
return `${(numberValue * 1000).toFixed(decimal)} kW`;
}

for (const rule of rules) {
if (Math.abs(numberValue) >= rule.threshold) {
const convertedValue = (numberValue / rule.divisor).toFixed(rule.decimal || decimal);
Expand Down

0 comments on commit 03b1da1

Please sign in to comment.