This is only a minor cosmetic issue but it’s stumping me…
I’m trying to get .format()
working to right-align a column of numbers in a $TableExpression
, and I can’t find the correct incantation… What am I doing wrong please? (I’ve searched the forum and can’t find this being addressed before…)
What I want is a column of numbers in a Summary table to be right aligned, with leading spaces/zeroes. E.g.
# Result
------------
1. 12.34
2. 1.23
3. -12.34
4. -1.23
Now, away from the Summary Table context (e.g. in a string attribute which can be displayed in outline columns or elsewhere), I can get this to work with:
$MyString = $MyNumber.format(2,10," ")
In the screenshot below, you can see that both $MyString (with .format(2,10," "
) and $FormattedStr (with .format(2,10,"-"
) produce the expected results in outline columns:
($FormattedNumber is a number attribute with .format(2,10," ")
and as you can the precision is respected, but not the leading padding, which isn’t unexpected as it’s not a string).
So far so good. But when I feed this into a $TableExpression, $FormattedSgt’s indenting is respected, but the leading spaces in $MyString are stripped out.
The $TableExpression is very simple:
$TableExpression='$Name + "|" + $MyNumber + "|" + $FormattedNumber + "|" + $MyString + "|" + $FormattedStr';
So there appears to be a difference in the way $TableExpression deals with .format(2,10," ")
and .format(2,10,"-")
compared to elsewhere in TBX.
Am I missing something?
Many thanks for your help.
[Edit: I thought I’d found a solution by using a non-breaking space in the format string, but that turns out to crash Tinderbox reliably, unfortunately.]