Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving bug for issue #665 and added a function for issue #667 #668

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -824,6 +845,8 @@ function formatOrDefault(providedFormat, defaultFormat) {
return providedFormat;
}



module.exports = (numbro) => ({
format: (...args) => format(...args, numbro),
getByteUnit: (...args) => getByteUnit(...args, numbro),
Expand Down