Skip to content

Commit

Permalink
fix: #261 q-numeric with 0.1 step lacks rounding
Browse files Browse the repository at this point in the history
Add "max-decimals" prop.
  • Loading branch information
rstoenescu committed Dec 18, 2016
1 parent 25cd706 commit 23d1a4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion dev/components/form/numeric.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
Model <span class="right-detail"><em>{{number}}</em> &nbsp;&nbsp;({{min}}-{{max}})</span>
</div>

<p class="caption">Standalone</p>
<p class="caption">Default</p>
<q-numeric v-model="number" :min="min" :max="max"></q-numeric>

<p class="caption">With Step 4</p>
<q-numeric v-model="number" :min="min" :max="max" :step="4"></q-numeric>

<p class="caption">With Step 0.2 & Maximum decimals 2</p>
<q-numeric v-model="numberPrecision" :min="min" :max="max" :step="0.2" :max-decimals="2"></q-numeric>

<p class="caption">Disabled State</p>
<q-numeric v-model="number" :min="min" :max="max" disable></q-numeric>

Expand Down Expand Up @@ -44,6 +50,7 @@ export default {
data () {
return {
number: 3,
numberPrecision: 5.15,
min: 1,
max: 1017
}
Expand Down
9 changes: 7 additions & 2 deletions src/vue-components/numeric/Numeric.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export default {
min: Number,
max: Number,
readonly: Boolean,
disable: Boolean
disable: Boolean,
maxDecimals: {
type: Number,
default: 0
}
},
watch: {
value () {
Expand All @@ -53,7 +57,8 @@ export default {
else if (typeof this.max === 'number' && value > this.max) {
return this.max
}
return value
return parseFloat(this.maxDecimals ? parseFloat(value).toFixed(this.maxDecimals) : value)
},
__updateValue () {
this.model = this.__normalize(this.model)
Expand Down

0 comments on commit 23d1a4d

Please sign in to comment.