Skip to content

Commit

Permalink
fix(amount): conversion of negative numbers to capitals (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyan0205 authored Jul 29, 2019
1 parent e32342d commit cafa5bb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions components/amount/number-capital.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ const cnDecUnits = ['\u89d2', '\u5206', '\u6beb', '\u5398']
const cnInteger = '\u6574' // 整 \u6574
const cnIntLast = '\u5143' // 元 \u5143

const cnNegative = '\u8d1f' // 负

// Maximum number
const maxNum = 999999999999999.9999

export default function(number) {
let negative
// Integral part
let integerNum
// Decimal part
Expand All @@ -31,6 +34,11 @@ export default function(number) {

number = parseFloat(number)

if (number < 0) {
negative = true
number = Math.abs(number)
}

/* istanbul ignore if */
if (number >= maxNum) {
return ''
Expand Down Expand Up @@ -94,5 +102,9 @@ export default function(number) {
} else if (decimalNum === '') {
capitalStr += cnInteger
}

if (negative) {
capitalStr = `${cnNegative}${capitalStr}`
}
return capitalStr
}

0 comments on commit cafa5bb

Please sign in to comment.