Skip to content

Commit b1e41dc

Browse files
committed
fix: improve calculatePercentage function and update documentation
- Update calculatePercentage function to use optional options object - Add new option to return percentage with symbol - Improve type definitions and documentation for better code clarity - Update round method in CalculatorChain class
1 parent 4266ec9 commit b1e41dc

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/finance/calculator.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,23 @@ export function compare(
103103
* @category Calculator
104104
* @param part 部分值
105105
* @param total 总值
106-
* @param decimalPlaces 小数位数
106+
* @param {object} [options] - 配置选项
107+
* @param {number} [options.decimalPlaces] - 小数位数
108+
* @param {boolean} [options.isSymbol] - 是否返回百分号
109+
* @returns 百分比值
107110
*/
108111
export function calculatePercentage(
109112
part: number | string,
110113
total: number | string,
111-
option?: {
114+
options?: {
112115
decimalPlaces?: number
113116
isSymbol?: boolean
114117
},
115118
): string {
116119
if (Number(total) === 0)
117120
return 'NaN'
118121

119-
const { decimalPlaces = 2, isSymbol = false } = option || {}
122+
const { decimalPlaces = 2, isSymbol = false } = options || {}
120123

121124
if (isSymbol) {
122125
return `${preciseDiv(part, total)
@@ -193,8 +196,8 @@ export class CalculatorChain {
193196

194197
/**
195198
* round
196-
* @param num 数字或字符串
197-
* @returns
199+
* @param decimalPlaces 数字或字符串
200+
* @returns Decimal
198201
*/
199202
round(decimalPlaces: number = 2): Decimal {
200203
return this.value.toDecimalPlaces(decimalPlaces)

0 commit comments

Comments
 (0)