aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-08-18 17:54:42 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-08-18 18:05:28 -0400
commit558ece8f6f1889bc4773432c16cdf96a54ec1431 (patch)
tree2db2cbdf0c76cd2a29e1dbb8f2a3efcc2c05d78a /std
parent33c592e981f93f207651b8353a8cbc3d09440353 (diff)
downloadzig-558ece8f6f1889bc4773432c16cdf96a54ec1431.tar.gz
zig-558ece8f6f1889bc4773432c16cdf96a54ec1431.zip
slightly nicer floating point printing
Diffstat (limited to 'std')
-rw-r--r--std/fmt/index.zig20
1 files changed, 14 insertions, 6 deletions
diff --git a/std/fmt/index.zig b/std/fmt/index.zig
index 012a65e01e..1366fd87d4 100644
--- a/std/fmt/index.zig
+++ b/std/fmt/index.zig
@@ -243,12 +243,20 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons
return false;
if (!output(context, "."))
return false;
- if (!output(context, float_decimal.digits[1..]))
- return false;
- if (!output(context, "e"))
- return false;
- if (!formatInt(float_decimal.exp, 10, false, 0, context, output))
- return false;
+ if (float_decimal.digits.len > 1) {
+ if (!output(context, float_decimal.digits[1 .. math.min(usize(7), float_decimal.digits.len)]))
+ return false;
+ } else {
+ if (!output(context, "0"))
+ return false;
+ }
+
+ if (float_decimal.exp != 1) {
+ if (!output(context, "e"))
+ return false;
+ if (!formatInt(float_decimal.exp, 10, false, 0, context, output))
+ return false;
+ }
return true;
}