diff options
author | Andrew Tridgell <tridge@samba.org> | 2013-04-25 22:22:16 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2013-05-04 19:18:29 +1000 |
commit | a153ee529f68e9b52805b8c77da1ec2bf0e54210 (patch) | |
tree | 540065780acf720779f4f5edf09eec42e9d34e78 /nuttx | |
parent | ff7712ca3e752141e54f3cbf15198a62429617f7 (diff) | |
download | px4-firmware-a153ee529f68e9b52805b8c77da1ec2bf0e54210.tar.gz px4-firmware-a153ee529f68e9b52805b8c77da1ec2bf0e54210.tar.bz2 px4-firmware-a153ee529f68e9b52805b8c77da1ec2bf0e54210.zip |
libdtoa: don't print trailing zeros if no decimal is printed
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/libc/stdio/lib_libdtoa.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/nuttx/libc/stdio/lib_libdtoa.c b/nuttx/libc/stdio/lib_libdtoa.c index 84e3ee50b..395a55b61 100644 --- a/nuttx/libc/stdio/lib_libdtoa.c +++ b/nuttx/libc/stdio/lib_libdtoa.c @@ -145,6 +145,7 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec, int nchars; /* Number of characters to print */ int dsgn; /* Unused sign indicator */ int i; + bool done_decimal_point = false; /* special handling for NaN and Infinity */ if (isnan(value)) { @@ -199,6 +200,7 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec, if (prec > 0 || IS_ALTFORM(flags)) { obj->put(obj, '.'); + done_decimal_point = true; /* Always print at least one digit to the right of the decimal point. */ @@ -224,6 +226,7 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec, /* Print the decimal point */ obj->put(obj, '.'); + done_decimal_point = true; /* Print any leading zeros to the right of the decimal point */ @@ -270,6 +273,7 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec, /* Print the decimal point */ obj->put(obj, '.'); + done_decimal_point = true; /* Always print at least one digit to the right of the decimal * point. @@ -306,8 +310,9 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec, } /* Finally, print any trailing zeroes */ - - zeroes(obj, prec); + if (done_decimal_point) { + zeroes(obj, prec); + } /* Is this memory supposed to be freed or not? */ |