summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2017-01-28 15:54:15 (EST)
committer P. J. McDermott <pj@pehjota.net>2017-01-28 15:54:15 (EST)
commit515f297d71ce6eebb193025d7f6d54e214852f4f (patch)
treeb70c220b1d9519cee04ef7c2064fe1b9a91349cc
parentab415b86b56d7dca2b31e82e0e1b9c0a884b8b21 (diff)
downloaddecmath.js-515f297d71ce6eebb193025d7f6d54e214852f4f.zip
decmath.js-515f297d71ce6eebb193025d7f6d54e214852f4f.tar.gz
decmath.js-515f297d71ce6eebb193025d7f6d54e214852f4f.tar.bz2
dfmt(): New function
-rw-r--r--lib/decmath.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/decmath.js b/lib/decmath.js
index ad79ec5..98c33e5 100644
--- a/lib/decmath.js
+++ b/lib/decmath.js
@@ -112,9 +112,20 @@ function drhfz(a, p)
return as.substr(0, as.length - p) + "." + as.substr(as.length - p);
}
+function dfmt(a, p)
+{
+ a = a.toString().split(".", 2);
+ if (a.length == 1) return null;
+ if (a[0] == "") a[0] = "0";
+ if (a[0] == "-") a[0] = "-0";
+ if (a[1].length < p) a[1] += Array(p - a[1].length + 1).join("0");
+ return a.join(".");
+}
+
if (typeof global != "undefined") {
global.dadd = dadd;
global.dmul = dmul;
global.drhtz = drhtz;
global.drhfz = drhfz;
+ global.dfmt = dfmt;
}