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?
Answer
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"
Comments
Post a Comment