From 384ee75e98daccfb078ee084edfdfa0b3188b79e Mon Sep 17 00:00:00 2001 From: Jann Horn Date: Wed, 30 Apr 2014 16:12:09 +0200 Subject: [PATCH] round:output without comma for integer targets --- math/round.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/math/round.c b/math/round.c index f87d3c1..f5a07b2 100644 --- a/math/round.c +++ b/math/round.c @@ -1,9 +1,11 @@ #include #include +#include int main(int argc, char **argv) { if (argc != 2) xperror("invocation: round ", 0); double target = strtod(argv[1], NULL); + bool intmode = (target == floor(target)); char line[128]; while (fgets(line, sizeof(line), stdin)) { trim_end(line, "\r\n \t"); @@ -12,7 +14,11 @@ int main(int argc, char **argv) { double quot = n / target; quot = round(quot); n = quot * target; - printf("%f\n", n); + if (intmode) { + printf("%lld\n", (long long)n); + } else { + printf("%f\n", n); + } } return 0; } -- 2.20.1