Re: sprintf does not round floating point numbers

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



In the format string, specify exact number of digits you want after the
floating point (less that full precision). Then the last 1 will be
discarded.

"David Liebtag" <DavidLiebtag@xxxxxxxxxxxxx> wrote in message
news:%237r1DcdHGHA.2064@xxxxxxxxxxxxxxxxxxxxxxx
> Folks,
>
> I transcribed the sprintf output incorrectly. We do indeed get:
>
> +1.0000000000000001E-1 with Visual Studio
> +1.0000000000000000E-1 with the old compiler
>
> I fully understand that the least significant digit is not reliable, and
> that our users should not depend on it. Actually, our product uses the
> sprintf result as an intermediate value and strips trailing zeros before
> returning the value to the user. Since the VS result does not have
> trailing zeros, our users are getting different results than they are used
> to. We are trying to determine whether we should ignore the last digit,
> use a different control string, or return the full sprinf result.
>
> Victor Bazarov hinted at the information I'm searching for when he
> mentioned the C standard.
>
> Does the C standard specify which of the two values sprintf should
> produce?
>
> Thank you for your help and sorry for the confusion I caused by my
> incorrect transcription.
>
> David Liebtag
>
>


.



Relevant Pages

  • Re: [PHP] sprintf() oddness
    ... sprintf('%.03f', 0.15250000) ... The 4th significant digit in both cases is '5' but in the first case, ... Shouldn't rounding decisions be based on subsequent digits and not preceding ... What you describe is "if even then round down else round ...
    (php.general)
  • Re: [PHP] sprintf() oddness
    ... sprintf('%.03f', 0.15250000) ... The 4th significant digit in both cases is '5' but in the first case, ... it's more accurate to use the preceding digit to determine rounding. ... What you describe is "if even then round down else round up". ...
    (php.general)
  • Re: Number Formats
    ... This is by design, if a digit is 0, the # will automatically ignore it and ... display nothing. ... Please try to use a pre-defined format string like ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: printf problem
    ... digit numbers and here is the code I am working with right now. ... $bcol, and then printing $bcol. ... printfto sprintf() or eliminate $bcol entirely. ...
    (perl.beginners)
  • Re: decimal to hex ; using bc or other ?
    ... > output if the input results in a one digit answer. ... printf is your friend: ... man sprintf for format string guide ...
    (comp.unix.shell)