You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/02/01 18:52:22 UTC

[49/50] [abbrv] brooklyn-ui git commit: prevent more occational javascript 0.000000000001 doubles showing

prevent more occational javascript 0.000000000001 doubles showing


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/fbc41f05
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/fbc41f05
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/fbc41f05

Branch: refs/heads/0.5.0
Commit: fbc41f057e04c49305236e5d5c274db9b929d8d6
Parents: 1b12e3d
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Mar 25 18:40:21 2013 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Mar 25 18:40:21 2013 +0000

----------------------------------------------------------------------
 .../webapp/assets/js/libs/brooklyn-utils.js     | 25 ++++++++++++++++----
 1 file changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/fbc41f05/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js b/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js
index bf29825..b050132 100644
--- a/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js
+++ b/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js
@@ -36,14 +36,29 @@ function prep(s) {
 function roundIfNumberToNumDecimalPlaces(v, mantissa) {
     if (typeof v !== 'number')
         return v;
-    if (Math.round(v)==v)
-        return v;
     
-    var vk = v;
+    log("rounding")
+    log(v)
+    if (isWholeNumber(v))
+        return Math.round(v);
+    
+    var vk = v, xp = 1;
     for (i=0; i<mantissa; i++) {
         vk *= 10;
-        if (Math.round(vk)==vk)
-            return v;
+        xp *= 10;
+        if (isWholeNumber(vk)) {
+            log("bailing")
+            log(vk)            
+            log(Math.round(vk)/xp);
+            return Math.round(vk)/xp;
+        }
     }
+    log("toFixed")
+    log(Number(v.toFixed(mantissa)))
     return Number(v.toFixed(mantissa))
 }
+
+function isWholeNumber(v) {
+    return (Math.abs(Math.round(v) - v) < 0.000000000001);
+}
+