[Pkg-javascript-commits] [dojo] 68/87: Fixes #16411. IE only needed a workaround for rounding [0.5, 0.95) instead [0.5, 1.0). Added automated tests. !strict
David Prévot
taffit at moszumanska.debian.org
Thu Aug 21 17:39:22 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.7.5
in repository dojo.
commit 5cb4b5cfa05f92b25f1169cb5dbc466b253e23ee
Author: Douglas Hays <doughays at dojotoolkit.org>
Date: Fri Nov 30 18:21:42 2012 +0000
Fixes #16411. IE only needed a workaround for rounding [0.5,0.95) instead [0.5,1.0). Added automated tests. !strict
git-svn-id: http://svn.dojotoolkit.org/src/branches/1.7/dojo@30094 560b804f-0ae3-0310-86f3-f6aa0a117693
---
number.js | 7 ++++++-
tests/number.js | 5 +++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/number.js b/number.js
index eba7616..f88b367 100644
--- a/number.js
+++ b/number.js
@@ -145,8 +145,13 @@ if((0.9).toFixed() == 0){
var round = dojo.number.round;
dojo.number.round = function(v, p, m){
var d = Math.pow(10, -p || 0), a = Math.abs(v);
- if(!v || a >= d || a * Math.pow(10, p + 1) < 5){
+ if(!v || a >= d){
d = 0;
+ }else{
+ a /= d;
+ if(a < 0.5 || a >= 0.95){
+ d = 0;
+ }
}
return round(v, p, m) + (v > 0 ? d : -d);
};
diff --git a/tests/number.js b/tests/number.js
index d30bcbe..170122c 100644
--- a/tests/number.js
+++ b/tests/number.js
@@ -171,6 +171,11 @@ doh.register("tests.number",
t.is(1, dojo.number.round(0.5));
t.is(-1, dojo.number.round(-0.5));
t.is(0.1, dojo.number.round(0.05, 1));
+ t.is(0.1, dojo.number.round(0.09, 1));
+ t.is(0.0, dojo.number.round(0.04999999, 1));
+ t.is(0.1, dojo.number.round(0.09499999, 1));
+ t.is(0.1, dojo.number.round(0.095, 1));
+ t.is(0.1, dojo.number.round(0.09999999, 1));
t.is(-0.1, dojo.number.round(-0.05, 1));
t.is(1.1, dojo.number.round(1.05, 1));
t.is(-1.1, dojo.number.round(-1.05, 1));
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git
More information about the Pkg-javascript-commits
mailing list