Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling DoubleToStringConverter::ToShortest with the value 1.80113 generates the string 1.8011300000000001 #84

Open
troelstm opened this issue Nov 23, 2018 · 3 comments
Assignees

Comments

@troelstm
Copy link

The produced output 1.8011300000000001 is at least not what I would expect from ToShortest.

This code path doesn't generate a fallback to bignum calculations. I can't fully deduce from the comments whether this is intentionally.

But the net outcome is that this makes ToShortest a no go for our usage.

We have implemented an overlay of ToShortest that takes an additional max_digits input that we can use to solve the problem, but I'm wondering whether there is a better / more general solution.

@floitsch floitsch self-assigned this Nov 26, 2018
@floitsch
Copy link
Collaborator

floitsch commented Dec 3, 2018

I just tried to reproduce, but was unsuccessful.
Could you provide more information on how you get this result.

The following worked in the test-program:

  const int kBufferSize = 128;
  char buffer[kBufferSize];
  StringBuilder builder(buffer, kBufferSize);
  int flags = DoubleToStringConverter::UNIQUE_ZERO |
      DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN;
  DoubleToStringConverter dc(flags, NULL, NULL, 'e', -6, 21, 0, 0);

  CHECK(dc.ToShortest(1.80113, &builder));
  CHECK_EQ("1.80113", builder.Finalize());

@Rayanysilva
Copy link

Uploading photo-20220205-0925107726222621190581234.jpg…

@Rayanysilva
Copy link

Para de mandar mensagem para minha esposa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants