Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

20
  • $\begingroup$ In the linked question I've already found a faster alternative to Internal`DoubleToString: it is DecimalForm combined with SetPrecision. The problem is that it doesn't allow to recover the original decimal representation of the numbers exactly (as well as Internal`DoubleToString). $\endgroup$ Commented May 17, 2018 at 8:02
  • $\begingroup$ @AlexeyPopkov That faster alternative is quite a fine example of what in Russia we call костыли. Anyway, your words "the original decimal representation" suggest some confusion about they way, numbers are handled, at least on an intuitive level. In the case of your linked question, the numbers cannot and will not be "exactly" represented (your complaint about the changing last digit). If you want an exact decimal representation, you should input numbers with arbitrary precision, e.g. -56705.907687414737`17. (cont'd) $\endgroup$ Commented May 17, 2018 at 8:14
  • $\begingroup$ Note, then, that x = -56705.907687414737; y = -56705.907687414737`17; ExportString[{x,y},"TSV"] will return -56705.907687414736 -56705.907687414737. Besides that, you say that DecimalForm[-38741.90768741473, Infinity] changes the last digit to 2. I, unfortunately, don't have v11.3 to test with, but both InputForm and DoubleToString show me the exact input, regardless if the last digit is 2 or 3. This seems to be a bug of DecimalForm $\endgroup$ Commented May 17, 2018 at 8:20
  • $\begingroup$ @AlexeyPopkov anyway, it would be helpful if you specify your problem more completely (including the background). Why exactly do you care specifically about the decimal representation of your numbers when they, likely have been obtained through calculations with binary double-precision floats? If that is not the case, then calculations ought to have been done in arbitrary precision, in which case the numbers should be stored as such. In this case, their InputForm and/or ToString, etc conserves their decimal representation to the arbitrary precision that was given. $\endgroup$ Commented May 17, 2018 at 8:24
  • $\begingroup$ The numbers are generated by another application and then Imported by Mathematica. Export allows to generate exactly the same file, but very slow. My goal is to add two columns into that TSV file. $\endgroup$ Commented May 17, 2018 at 8:27