4

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.

Johu
  • 4,918
  • 16
  • 43

2 Answers2

5

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

SetOptions[StringTemplate, InsertionFunction -> ToString]
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
2

Looks like a bug, here is simple workaround:

StringTemplate["A: ``"]@ToString@%
"A: 6.63e-34" 
Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368