aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-06-27 11:29:37 +0300
committermax99x <max99x@gmail.com>2011-06-27 11:29:37 +0300
commit6d6c9c4171fbb37dc2834d701fdb4497a7753da6 (patch)
tree59a956f465367dfe9021b5ce374c12f77febda87 /src
parent24f83c080f90dc440bd4981fc9ba5661b7bc28db (diff)
Minor printf() bugfix.
Diffstat (limited to 'src')
-rw-r--r--src/library.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/library.js b/src/library.js
index 97407a1f..19970840 100644
--- a/src/library.js
+++ b/src/library.js
@@ -314,6 +314,8 @@ var Library = {
}
}
+ var dropTrailingZeros = isGeneral && !flagAlternative;
+
// Round or pad a fractional part given the current precision.
var applyPrecision = function(fractionPart) {
if (precision == 0) {
@@ -324,12 +326,12 @@ var Library = {
while (fractionPart.length < precision) {
fractionPart = '0' + fractionPart;
}
- } else {
+ } else if (!dropTrailingZeros) {
while (fractionPart.length < precision) {
fractionPart += '0';
}
}
- if (isGeneral && !flagAlternative) {
+ if (dropTrailingZeros) {
while (fractionPart[fractionPart.length - 1] == '0') {
fractionPart = fractionPart.slice(0, -1);
}
@@ -361,10 +363,12 @@ var Library = {
fractionPart = '';
}
parts.push(wholePart || '0');
+ fractionPart = applyPrecision(fractionPart);
if (fractionPart) {
parts.push('.');
- fractionPart = applyPrecision(fractionPart);
- if (parseInt(fractionPart, 10) > 0) parts.push(fractionPart);
+ if (!dropTrailingZeros || parseInt(fractionPart, 10) > 0) {
+ parts.push(fractionPart);
+ }
} else if (flagAlternative) {
parts.push('.');
}