From e1b753f7979f1f5fe30d463b26a0cbafc8b24ad5 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sun, 15 Dec 2013 00:18:03 -0500 Subject: [PATCH] tweaking general format [ci skip] --- ssf.js | 4 ++-- ssf.md | 7 ++++--- ssf_node.js | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ssf.js b/ssf.js index 4135e3b..d16b6b5 100644 --- a/ssf.js +++ b/ssf.js @@ -1,5 +1,5 @@ /* ssf.js (C) 2013 SheetJS -- http://sheetjs.com */ -var SSF; +var SSF = {}; (function(SSF){ String.prototype.reverse=function(){return this.split("").reverse().join("");}; var _strrev = function(x) { return String(x).reverse(); }; @@ -86,7 +86,7 @@ var frac = function(x, D, mixed) { var general_fmt = function(v) { if(typeof v === 'boolean') return v ? "TRUE" : "FALSE"; if(typeof v === 'number') { - return v.toString().substr(0,11); + return v.toPrecision(10).replace(/\.0*$/,"").replace(/\.(.*[^0])0*$/,".$1"); } if(typeof v === 'string') return v; throw "unsupport value in General format: " + v; diff --git a/ssf.md b/ssf.md index b874a9f..7dc57b3 100644 --- a/ssf.md +++ b/ssf.md @@ -134,11 +134,12 @@ Booleans are serialized in upper case: if(typeof v === 'boolean') return v ? "TRUE" : "FALSE"; ``` -For numbers, try to display up to 11 digits of the number: +For numbers, try to display up to 11 digits of the number (the original code +`return v.toString().substr(0,11);` was not satisfactory in the case of 11 2/3) ``` if(typeof v === 'number') { - return v.toString().substr(0,11); + return v.toPrecision(10).replace(/\.0*$/,"").replace(/\.(.*[^0])0*$/,".$1"); } ``` @@ -737,7 +738,7 @@ var frac = function(x, D, mixed) { ```js>tmp/00_header.js /* ssf.js (C) 2013 SheetJS -- http://sheetjs.com */ -var SSF; +var SSF = {}; (function(SSF){ String.prototype.reverse=function(){return this.split("").reverse().join("");}; var _strrev = function(x) { return String(x).reverse(); }; diff --git a/ssf_node.js b/ssf_node.js index 0c839f3..04aa895 100644 --- a/ssf_node.js +++ b/ssf_node.js @@ -1,5 +1,5 @@ /* ssf.js (C) 2013 SheetJS -- http://sheetjs.com */ -var SSF; +var SSF = {}; (function(SSF){ String.prototype.reverse=function(){return this.split("").reverse().join("");}; var _strrev = function(x) { return String(x).reverse(); }; @@ -86,7 +86,7 @@ var frac = function(x, D, mixed) { var general_fmt = function(v) { if(typeof v === 'boolean') return v ? "TRUE" : "FALSE"; if(typeof v === 'number') { - return v.toString().substr(0,11); + return v.toPrecision(10).replace(/\.0*$/,"").replace(/\.(.*[^0])0*$/,".$1"); } if(typeof v === 'string') return v; throw "unsupport value in General format: " + v;