4
$\begingroup$

I am trying to write Latex report generator for my standard data analysis. But there is an issue with formatting numbers I can not get around. I would like to make use of my own NumberFormat and StringTemplatess but the last reformats the numbers. Here is an example:

n = QuantityMagnitude@UnitConvert@Quantity["PlanckConstant"]

6.626070*10^-34

ScientificForm[n, 3, 
 ExponentFunction -> (If[-10 < # < 10, Null, #] &), 
 NumberFormat -> (If[#3 != "", Row[{#1, "e", #3}], #1] &)]

6.63e-34

StringTemplate["A: ``"]@%

A: 0.00000000000000000000000000000000066260696

Is there a way to make StringTemplate output the numbers in a format I have specified? I guess the problem might have something to do with underlying TextString.

$\endgroup$
5
$\begingroup$

The default InsertionFunction for StringTemplate is TextString; use ToString instead:

SetOptions[StringTemplate, InsertionFunction -> ToString]
$\endgroup$
2
$\begingroup$

Looks like a bug, here is simple workaround:

StringTemplate["A: ``"]@ToString@%
"A: 6.63e-34" 
$\endgroup$

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.