Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Simple question: formatting numeric data
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1357202418

Message started by J Fallows on Jan 3rd, 2013, 3:40am

Title: Simple question: formatting numeric data
Post by J Fallows on Jan 3rd, 2013, 3:40am

I am sure there is an answer to this in the Help and A TB Ref files, but for some reason I cannot find it.

Challenge: I want to display numeric data in a normal currency-style format. I have a list of figures that are either whole numbers or that have two decimal places; they're all dollar figures. In a spreadsheet, I can easily choose to have them displayed this way:
† †500.00
† † †22.50
1,000.00
† † † 2.25
† † † † .10
1,524.85 Total

If the formatting doesn't survive my posting, the intent is to have decimal points aligned, and for all numbers to display two digits after the decimal point.

In TB I get the same list of numbers looking like this
500
22.5
1000
2.25
.1
1524.85 †total

Ie, they are left-aligned, and they display 0, 1, or 2 decimal-point digits. †I see in the Help and Ref files that the proper formatting command would be †" †.format($MyNumber,2) †" and I have added that to the agent collecting and displaying this data. But I still get the non-formatted display. I also get that if I am displaying the numbers in a column in an outline view.

What is the obvious point I am missing? On looking through the forum, I see that there was a similar question three years ago:
http://www.eastgate.com/Tinderbox/forum//YaBB.pl?num=1239652305/0#0

Thanks once more.

Title: Re: Simple question: formatting numeric data
Post by Mark Anderson on Jan 3rd, 2013, 7:37am

There is no single function that, applied to text will find and decimal point align a series of numbers. This may be the answer to your question (i.e. to stop looking further), especially if your number data is being hand entered into $Text or is being imported as $Text from some other document (e.g. dragging in tab-delim data). A better solution might be to make a stamp that passed current $Text to the command line and then used PERL, Ruby, whatever, to convert any paragraphs (i.e. lines) beginning with a digit character into the correct format and return the correctly formatted string. Those languages aren't my area of expertise, but there are folk around here who might be able to help. I can see some assumptions/tests needed - is there more than one block of numbers in the input string and what is the longest number in each set of numbers (and indeed is that the last line in each set, e.g. a total).

What follows is an exploration of TB code possibilities which are not necessarily practical for most users. So, please don't rush point out that obvious fact!

Well, I just deleted a long exploratory answer and instead packed the concept into a re-written aTbRef article on Number.format(). Give that a read - questions welcomed.

Title: Re: Simple question: formatting numeric data
Post by J Fallows on Jan 3rd, 2013, 11:59am

Mark A: thanks for the explanation. I am perversely relieved to find that there is not some obvious RTFM-type solution that I missed.

Mark B and various Tinderbox folk: might this be worth considering for the gala, still-in-production TB6? It's great that TB offers a wide variety of formatting options for calendar dates. I suspect I am not the only user who would find it handy to be able to format numbers as well -- in particular, to present a very frequently used type of number, dollar-based data, in the most frequently used format. Just a thought.

Title: Re: Simple question: formatting numeric data
Post by Mark Anderson on Jan 3rd, 2013, 12:44pm

FWIW, I've already submitted a feature suggestion that might make it easier to calculate the 'widest' of a set of numbers to assist with easier column formatting. However note that TB's $Text doesn't - certainly as at v5.x - set out to be a fully word-processor type environment with paragraph styles, tables, lists, etc. IOW, whilst setting the $Text to be a just a decimal point aligned list of figures isn't too hard (even now) you  still can't easily select lines (paragraphs) with figures, for example $Text lines #5 through #9 and then tell TB to just format those as such a list. The latter's more in the realm of a full text layout app.

There's essentially tension of conflicting requirements here between those who just want to write (in final output form) in TB and those who want to do analysis of text and other data and have less need of the complexity of complex formatting. The more complex the writing/formatted space, the harder - or more limited - the analysis becomes. Or certainly that's true in the v5 architecture. No idea how, if any, the v6 move to a Cocoa architecture is going to help balance those two ends.

Title: Re: Simple question: formatting numeric data
Post by J Fallows on Jan 3rd, 2013, 6:15pm

Right, I do understand that TB's ambitions, though impressive, do not and should not extend to being a fully-featured word processing (and formatting) system.

The number-formatting issue seemed to me a separate case, specifically comparable to the date-formatting features that TB does offer. But I have no way of judging the programming tradeoffs that would be involved in bringing this about, and I leave that to the pros.

Title: Re: Simple question: formatting numeric data
Post by Mark Bernstein on Jan 3rd, 2013, 6:44pm

My expectation has been that, if you want a nicely formatted report like this -- something where you care about alignment -- you'd set it up in HTML. †Either directly:

<td class="dollars"> ^value($Price).format(2) </td>

or using a visual HTML editor like Coda to do the template. †

- - - - -

I'm quite happy to add a field width to the format() command. But that will only work in monospace fonts, of course.

Title: Re: Simple question: formatting numeric data
Post by tadmcnulty on Jan 23rd, 2015, 4:38am

I had been racking my brains for the reason why the decimal places in a column of numbers were not lining up vertically when I formatted a common width using Number.format(decimalsN[,widthN]).


Quote:
that will only work in monospace fonts, of course.


Indeed! (Hadnít thought about the variable width of numbers in a variable-width font).

FWIW, like J Fallows, I would find some basic number formatting options useful as well, not only for an exported report but for the tbx document itself, so that the spreadsheet for ideas can display those related to numbers a little more clearly.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.