diff options
author | P. 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) |
commit | 515f297d71ce6eebb193025d7f6d54e214852f4f (patch) | |
tree | b70c220b1d9519cee04ef7c2064fe1b9a91349cc /lib | |
parent | ab415b86b56d7dca2b31e82e0e1b9c0a884b8b21 (diff) | |
download | decmath.js-515f297d71ce6eebb193025d7f6d54e214852f4f.zip decmath.js-515f297d71ce6eebb193025d7f6d54e214852f4f.tar.gz decmath.js-515f297d71ce6eebb193025d7f6d54e214852f4f.tar.bz2 |
dfmt(): New function
Diffstat (limited to 'lib')
-rw-r--r-- | lib/decmath.js | 11 |
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; } |