Merge branch 'dev' of codeup.aliyun.com:61c14a7efa282c88e103c23f/oak-domain into dev

This commit is contained in:
Xu Chang 2023-11-15 18:32:41 +08:00
commit f641a86710
3 changed files with 25 additions and 5 deletions

View File

@ -2,5 +2,5 @@ declare const ToCent: (float: number) => number;
declare const ToYuan: (int: number) => number;
declare const StringToCent: (value: string, allowNegative?: true) => number | undefined;
declare const CentToString: (value: number) => string | undefined;
declare const ThousandCont: (value: number) => string | undefined;
declare const ThousandCont: (value: number, decimalPlaces?: number) => string | undefined;
export { ToCent, ToYuan, StringToCent, CentToString, ThousandCont };

View File

@ -22,7 +22,7 @@ const CentToString = (value) => {
}
};
exports.CentToString = CentToString;
const ThousandCont = (value) => {
const ThousandCont = (value, decimalPlaces) => {
let value1 = `${value}`;
const numArr = value1.split('.');
value1 = numArr[0];
@ -34,7 +34,18 @@ const ThousandCont = (value) => {
if (value1) {
result = value1 + result;
}
result = numArr[1] ? result + '.' + numArr[1] : result;
if (decimalPlaces && decimalPlaces > 0) {
if (numArr[1]) {
const decimalPart = numArr[1].padEnd(decimalPlaces, '0').slice(0, decimalPlaces);
result = result + '.' + decimalPart;
}
else {
result = result + '.' + '0'.repeat(decimalPlaces);
}
}
else {
result = numArr[1] ? result + '.' + numArr[1] : result;
}
return result;
};
exports.ThousandCont = ThousandCont;

View File

@ -22,7 +22,7 @@ const CentToString: (value: number) => string | undefined = (value) => {
}
};
const ThousandCont: (value: number) => string | undefined = (value) => {
const ThousandCont: (value: number, decimalPlaces?: number) => string | undefined = (value, decimalPlaces) => {
let value1 = `${value}`;
const numArr = value1.split('.');
value1 = numArr[0];
@ -34,7 +34,16 @@ const ThousandCont: (value: number) => string | undefined = (value) => {
if (value1) {
result = value1 + result;
}
result = numArr[1] ? result + '.' + numArr[1] : result;
if (decimalPlaces && decimalPlaces > 0) {
if (numArr[1]) {
const decimalPart = numArr[1].padEnd(decimalPlaces, '0').slice(0, decimalPlaces);
result = result + '.' + decimalPart;
} else {
result = result + '.' + '0'.repeat(decimalPlaces);
}
} else {
result = numArr[1] ? result + '.' + numArr[1] : result;
}
return result;
};