Skip to content

Commit

Permalink
fix(amount): fix amount display negative number (#645)
Browse files Browse the repository at this point in the history
* fix(amount): fix amount display negative number

fix #644

* fix(amount): change variable name

fix #644
  • Loading branch information
supergaojian authored Feb 4, 2020
1 parent 4a451ac commit 8eebc67
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions components/amount/demo/cases/demo1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<md-amount
:value="1234"
has-separator
></md-amount>
<br>
<md-amount
:value="-123456.123"
:precision="3"
has-separator
></md-amount>
</div>
</template>
Expand Down
11 changes: 9 additions & 2 deletions components/amount/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ export default {
}
const numberParts = value.split('.')
const integerValue = numberParts[0]
let integerValue = numberParts[0]
const decimalValue = numberParts[1] || ''
let sign = ''
if (integerValue.startsWith('-')) {
integerValue = integerValue.substring(1)
sign = '-'
}
const formateValue = formatValueByGapStep(3, integerValue, separator, 'right', 0, 1)
return decimalValue ? `${formateValue.value}.${decimalValue}` : `${formateValue.value}`
return decimalValue ? `${sign}${formateValue.value}.${decimalValue}` : `${sign}${formateValue.value}`
},
doCapital(value) {
return numberCapital(value)
Expand Down
2 changes: 1 addition & 1 deletion components/amount/test/__snapshots__/demo.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ exports[`Amount -Demo Basic 1`] = `

exports[`Amount -Demo Disabled unselected 1`] = `<div class="md-example-child md-example-child-amount"><span class="md-amount"> 壹仟贰佰叁拾肆元整 </span> <span class="md-amount"> 壹拾贰元叁角肆分 </span> <span class="md-amount"> 壹仟贰佰元整 </span> <span class="md-amount"> 壹仟贰佰零壹元整 </span></div>`;

exports[`Amount -Demo Thousands Separator 1`] = `<div class="md-example-child md-example-child-amount"><span class="md-amount numerical">1,234.00</span></div>`;
exports[`Amount -Demo Thousands Separator 1`] = `<div class="md-example-child md-example-child-amount"><span class="md-amount numerical">1,234.00</span> <br> <span class="md-amount numerical">-123,456.123</span></div>`;
exports[`Amount -Demo Transition 1`] = `<div class="md-example-child md-example-child-amount"><span class="md-amount numerical">0.00</span></div>`;
6 changes: 6 additions & 0 deletions components/amount/test/cases/demo1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<md-amount
:value="1234"
has-separator
></md-amount>
<br>
<md-amount
:value="-123456.123"
:precision="3"
has-separator
></md-amount>
</div>
</template>
Expand Down

0 comments on commit 8eebc67

Please sign in to comment.