Files
DiceCloud/app/imports/api/utility/numberToSignedString.js
2023-06-14 13:57:30 +02:00

12 lines
450 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export default function numberToSignedString(number, spaced) {
if (typeof number !== 'number') return number;
if (number === 0) {
return spaced ? '+ 0' : '+0';
} else if (number > 0) {
return spaced ? `+ ${number}` : `+${number}`;
} else {
// Uses the unicode minus sign '' instead of a dash '-' to help line up numbers nicely
return spaced ? ` ${Math.abs(number) || number}` : `${Math.abs(number) || number}`;
}
}