diff --git a/src/formatting.js b/src/formatting.js index 270c952f..2276536a 100644 --- a/src/formatting.js +++ b/src/formatting.js @@ -331,9 +331,9 @@ function formatCurrency(instance, providedFormat, state) { if (position === "prefix") { if (instance._value < 0 && options.negative === "sign") { - output = `-${space}${symbol}${output.slice(1)}`; + output = `${symbol}${space}-${output.slice(1)}`; } else if (instance._value > 0 && options.forceSign) { - output = `+${space}${symbol}${output.slice(1)}`; + output = `${symbol}${space}+${output.slice(1)}`; } else { output = symbol + space + output; } @@ -804,13 +804,34 @@ function formatNumber({ instance, providedFormat, state = globalState, decimalSe return output; } +/** + * It will fix the floating point format + * Return the correct decimal display of number for the given minimum and maximum length + * @param {number} num - The number you want to fix the format. + * @param {number} min - The minimum number of decimal + * @param {number} max - The maximum number of decimal + */ + +function fixFloatingfFormat(num, min, max) { + dec_str = num.toString().split('.')[1] + dec_num = dec_str.length + if (dec_num < min) { + dec_num = min + } else if (dec_num > max) { + dec_num = max + }; + return num.toFixed(dec_num) +} + /** * If FORMAT is non-null and not just an output, return FORMAT. * Return DEFAULTFORMAT otherwise. * * @param providedFormat * @param defaultFormat + * */ + function formatOrDefault(providedFormat, defaultFormat) { if (!providedFormat) { return defaultFormat; @@ -824,6 +845,8 @@ function formatOrDefault(providedFormat, defaultFormat) { return providedFormat; } + + module.exports = (numbro) => ({ format: (...args) => format(...args, numbro), getByteUnit: (...args) => getByteUnit(...args, numbro),