7
$\begingroup$

Bug introduced in 10.4 or earlier and fixed in 12.0
Bug isn't present in version 10.0.1


I'm using Mathematica 10.4 on Windows 7 and I found out that

StringTemplate["``"][NumberForm[1000/81, 10]]

Gives

"12.34567901"

Which is correct, but

StringTemplate["``"][NumberForm[-1000/81, 10]]

Only returns with the rounded integer

"-12"

I need to print an array of positive and negative numbers in a specific format. How I can bypass this problem?

$\endgroup$
  • 1
    $\begingroup$ This question is very similar to (125006). $\endgroup$ – WReach Sep 11 '16 at 13:34
5
$\begingroup$

This is a bug in StringTemplate. One workaround is to preliminarily convert NumberForm into string by applying ToString. Note that NumberForm isn't intended for working with exact rationals and hence you need also to apply N to the first argument of NumberForm:

StringTemplate["``"][ToString@NumberForm[N[-1000/81], 10]]
"-12.34567901"

Here is a minimal working example demonstrating the bug (the output is identical in versions 10.4.1 and 11.0.0):

StringTemplate["``"][NumberForm[N[-1000/81], 10]]
"-12"

Version 10.0.1 has no bug and creates correct output even without applying N to the first argument of NumberForm:

StringTemplate["``"][NumberForm[-1000/81, 10]]
"-12.34567901"
$\endgroup$
  • 1
    $\begingroup$ More specifically the bug was in TextString which is the default InsertingFunction for StringTemplate: TextString@NumberForm[-1000/81, 10]. $\endgroup$ – Kuba Aug 22 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.