Skip to content

Commit 947e76c

Browse files
committed
improve currency input example, fixes vuejs#887
1 parent dd00eba commit 947e76c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/v2/guide/components.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,12 @@ Vue.component('currency-input', {
619619
// Remove whitespace on either side
620620
.trim()
621621
// Shorten to 2 decimal places
622-
.slice(0, value.indexOf('.') + 3)
622+
.slice(
623+
0,
624+
value.indexOf('.') === -1
625+
? value.length
626+
: value.indexOf('.') + 3
627+
)
623628
// If the value was not already normalized,
624629
// manually override it to conform
625630
if (formattedValue !== value) {
@@ -653,7 +658,12 @@ Vue.component('currency-input', {
653658
updateValue: function (value) {
654659
var formattedValue = value
655660
.trim()
656-
.slice(0, value.indexOf('.') + 3)
661+
.slice(
662+
0,
663+
value.indexOf('.') === -1
664+
? value.length
665+
: value.indexOf('.') + 3
666+
)
657667
if (formattedValue !== value) {
658668
this.$refs.input.value = formattedValue
659669
}

0 commit comments

Comments
 (0)