printf %f - limiting the size of the outputted string ?

Giganews Newsgroups
Subject: printf %f - limiting the size of the outputted string ?
Posted by:  R.Wieser (addre…@not.available)
Date: Thu, 8 Aug 2019

Hello all,

I've been caught out a few times by an unexpected long result while printing
a float into a buffer using a "sprintf" function (several available, in (at
least) five different DLLs).

So, I did a google to determine the absolute maximum-to-be-expected size of
the outputted string, and found this:
https://www.exploringbinary.com/maximum-number-of-decimal-digits-in-binary-floating-point-numbers/

But even the size for a simple 8 byte float (standard under Windows) is a
whopping 309 chars.

Hence my question: Is there a method/function which limits the outputted
length ?    Something that will use the scientific "E" notation will do
fine.

Regards,
Rudy Wieser

Replies