Skip to content

Instantly share code, notes, and snippets.

@sjonkeesse
Last active March 25, 2016 15:30
Show Gist options
  • Save sjonkeesse/51ee1fb379da0e2befce to your computer and use it in GitHub Desktop.
Save sjonkeesse/51ee1fb379da0e2befce to your computer and use it in GitHub Desktop.
Wrong pointer value
import Ember from 'ember';
export default Ember.Controller.extend({
percentage: 0.21,
actions: {
increment(value) {
this.incrementProperty('percentage', value);
},
decrement(value) {
this.decrementProperty('percentage', value);
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
input[type="number"] {
width: 200px;
}
<h1>Wrong pointer value</h1>
<p>When incrementing or decrementing an pointervalue by .01, it often returns the wrong value. Also when the pointervalue is updated by one (not a decimal) it can sometimes do the same.<br>
For example: 0.03 + 0.01 = 0,0400000000000001</p>
<br /><br />
{{input type="number" value=percentage}} %
<br /><br />
<button {{action "increment" 0.01}}>Decrement (- 0.01)</button>
<button {{action "decrement" 0.01}}>Increment (+ 0.01)</button>
<br /><br />
<button {{action "increment" 1}}>Decrement (- 1)</button>
<button {{action "decrement" 1}}>Increment (+ 1)</button>
{
"version": "0.7.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment