From: Jann Horn Date: Wed, 30 Apr 2014 14:12:09 +0000 (+0200) Subject: round:output without comma for integer targets X-Git-Url: http://git.thejh.net/?p=tools.git;a=commitdiff_plain;h=384ee75e98daccfb078ee084edfdfa0b3188b79e;ds=sidebyside round:output without comma for integer targets --- 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; }