Tinderbox Forum

Creating an $Amount attribute & formatting its value

I’m creating an attribute for dollar amounts, and am trying to set it up properly. I’ve create an $Amount attribute, set the Number Data Type. So far, so good?

I’ve been reading through forum posts and aTbRef to understand how to set up Number.format() based on my number values and what I’m trying to do.

To quickly back up… I’m unable to import my numbers with decimals (because of the way I’m importing notes with values) so I’ll have to add them manually. I mention this only because I don’t know if it’ll affect the number formatting I’m seeking to do.

To that end, I’m wondering if it’s possible to combine the $MyNumber.format("l"); for comma separation and the $MyNumber.format("$"); to prefix numbers with dollar signs.


What? Can you expand this a bit. I sounds like you’d do better to fix your source data.

Why do you want a comma separator in a USD amount? What you are describing sounds like making a string $34,60 to represent 34 dollars and 60 cents.

Also , where are you wanting to show this sum? If, as I suspect, you mean showing it in Displayed Attributes the answer is ‘No’ as your $Amount is a number-type and, as documented, .format() applied to a number makes a string. You would have to have another string-type attribute to hold the output of the format.

I’m sorry to repeat, but if you’d share a small TBX file showing the problem, it would help explain it better for those of us trying to help—and to show how to apply a solution if there is one.

I’m using the MarginNote->OmniOutliner+Tinderbox rendering process, and then porting over notes to Tinderbox. Right now, I’m using hashtags for number amounts, although there might be a way to set up an Amount category (which could then become an $Amount attribute), such as the way we set up StartDate: [year/month/day]. I just didn’t want to trouble you with asking you about how to do that.

I guess I misread/misunderstood $MyNumber.format("l"); Basically, I’m just seeking a way to convert contiguous numbers (e.g., 12725) and convert them into $12,725.

Yes, but you don’t say where (and I did ask!). I’m not trying to be obtuse but it does matter as you can’t format as a displayed number. I’d note for other readers that as we’ve corresponded previously as some length via PM, I know more about the project than might seem apparent from this thread. You can re-format the number as a string but you can’t then, for instance show that string in a Displayed Attributes table cell that shows data from a Number cell as it can’t display a string.

Meanwhile, for currency and assuming you’re starting with $Amount value of ‘12725’ (i.e. 12725.0, there being no decimal component), the basic currency format—if you your Mac is set for a US locale—gives you a string like so:

$MyString = $Amount.format("$");

gives a $MyString of “$12,725.00”. Here in UK, using the same action code, I’d get “£12,725.00” and in Germany “€12.725,00”. In the last case note the thousands delimiter and decimal point differ to reflect that locale, in France it would be “€12,725.00”. So your OS locale setting alters what the “$” format returns.

Don’t want the decimal places? Use a format string of “$0” instead:

$MyString = $Amount.format("$0");

to get “$12,725”. But remember you can only display that in a string.

This is all documented a in aTbRef at Number.format(decimalsN[,widthN][,padStr]).

You did ask, and I somehow overlooked that. So, I was imagining that the numbers in question would fill the value(s) for the $Amount attribute. Does that answer your question?

This might be a stupid question, but: Can I still use a string if there are multiple number values?

Also, I’m working on a file that’s different than the one that we worked on together (though it’s using some elements of that file / approach), and so I’ve got a $MyString in use (and might even have a $MyString1 attribute). I’m guessing that means I should create a $MyString2 ?

Finally, I did look at the Number.format(decimalsN[,widthN][,padStr]) page and the Formatting for currency with/without decimal places post, and thought that I needed to combine two sets of code (hence the formatting question, which was based on my misapprehension). Anyway, because I might use numbers with & without decimals I thought that this might be the right approach…


If the string formulation is the way to go, I’ll give it a shot and report back.

@jprint714 I would recommend you revisit this process. Keep the number pure, e.g. 1100.24. In the attribute value, you don’t need nor want the common or currency designator. You can add these affordances in your export code. If you do it in the attribute value you’ll mess up your ability to sum value across notes.

1 Like

Sort of, but the answer is No for the the reasons already explained. $Amount is a Number-type attribute. Using .format() on a number gives a String. So, no go!

Insufficient info. Use a string to do what?

I’m $MyString as an example, to indicate data type—in keeping with all the aTbRef examples. IOW, the attribute to which you pass the string must be of String data-type. What you call that attribute in your own work is up to you: ‘MyString’, ‘SomeResult’, ‘the_name’, whatever… :slight_smile:

I’ve no idea how you get to that. I gave you two different code examples and explained the different result. If $Amount held the value 12725 on a US system your code would result in a single string value “$12,725.00$12,725”. I’m sure that isn’t what you want.

Please, again, post a small TBX showing the problem or the starting point you have and a with a note explaining the desired out code or a note hand-set to the values you desire to be made via action code.

Thanks, @satikusala. Appreciate that. I’m working on trying to fix it, along with shoring up other parts of the file. Thanks for your helpful input.

I’m still working on solutions to import number data into Tinderbox. I’ve been hesitant to ask these questions, because I fear they’re elementary, but I’m wondering the following…

-As I understand it, String data types are singular values; you can’t have more than one string value, is that correct?

-As I understand it, one can’t have things like dollar signs and commas for number data types. Is that right?

-If that’s an accurate assessment, wouldn’t it be better to put numbers that have both commas and dollar signs in a set or list data type?


The question is, do you want to do arithmetic or other calculations?

If so, you should strip currency symbols and thousands separators before import. This is true of most everything — spreadsheets, for example.

If not, leave things as strings.

1 Like

Ok, thanks. I don’t plan to calculate these numbers, so I don’t need a Number data type.

I’m sorry, I still don’t understand strings and how they’re supposed to work. I understood that they had a singular value, and set and lists were designed for multi-value data types. Can someone clarify this further for me. I know this is quite basic…. Thanks!

A string is just a piece of text. So “Hello World” is a string, but so is “12345” if it is put into an attribute holding a string instead of a number attribute.

I think you are probably getting strings confused with sets and lists.

Edit: and in case that isn’t clear, both sets and lists contain strings.

1 Like

Thanks. Appreciate that. But I thought a string data type can just have one value — not multiple values like set or list data types. Is that right?

That’s right.

For example, John has 350 gold pieces


On the other hand, John has a hat, a lantern, and a map.


Whatever John has, Ivan can have his own stuff.


At the risk of creating confusion, but hoping that it provides illumination instead, here is a handy list of attributes that have the String data type:


As you will see, there are lots of them!

1 Like

Although, for good reason, we have many discrete data types, there are really only 4 major ones as most as a special form of String-type, as I describe here.

In that same article I’ve annotated another axis of difference: single value vs. multi-value. All multi-valued data types are essentially string-based. This doesn’t mean you can’t store a list of numbers or datas, but some care may be needed when reading values back from the list if wishing to do non-String operations on the value, e.g. multiply a number value.

1 Like

For those that might be confused about the above post, here is an attached file to explain this a bit more.

String; a string is a list of characters, a string can hold from 0 to 100,000+ characters (I actually don’t know the limit)
List: list of strings separated by semicolons, e.g. “Hat;Latern;Map;Candle;Hat;.” lists allow duplicates.
Set: a set is l list that is automatically alphanumeric sorted and does not all duplicates, it will automatically strip out any duplicates e.g. “Candle:Hat;Latern;Map”
Number: Is a number, e.g. 1000.50
Boolean: is a true or false statement, true the boolean is scheduled, false the boolean is not checked. In Boolean a 1 is equal to true and a 0 is false.

Action Code
Action code is a Tinderbox scripting language that allows you to assign and transform values in an attribute. There are many places action code can be used in Tinderboxf, e.g. Rules, Adictios, OnAdds, OnRemoves, in export code (when founded by an export action), macros, etc. In action code, a single = means assign the result of the expression on the right of the equals to the attribute (or variable) and the left side of the equals.

e.g. `$Gold(“John”)=350.5;’ means make the value of the $Gold attribute in the first instance of the uniquely named note “John” is a number $350.5.

REMEMBER: the value in the parenthetical quotes on the left side of the =, e.g. “John”, is the unique name of a note or the path to this note.

Try It Yourself*
Now try it yourself. Download the attached file.

  1. In the stamp, change the value of the numbers for $Gold and $Items, e.g. make $Gold $400.25 and change or add some items (remember to separate each item with a semicolon). In this case, $Items is a set so it won’t keep duplicates (so, even though $Items has “Hat” twice Tinderbox won’t save the second instance and it alphabetically resorts to the set),
  2. Select all three notes and apply the stamp. Note how only the first note named John changes, as is the first uniquely named note John. In the last expression $IsGold350 I’m testing every note to see if the attribute value of gold is greater than 350. It is every note because, as you see, I’m not testing for a specific unique note name, e.g. “John”, with the parenthetical argument. Also, see how I can use a number for the result of the boolean in the GoldGT350. GT is for greater than. I can set the boolean operation with a String as well.

TBX L - Strings, Numbers and Sets.tbx (80.4 KB)

1 Like

Thanks so much for all of your help trying to explain the concept of string. I greatly appreciate it. I guess the one point I’m trying to reconcile in my mind is how string can have a singular value – while at the same time having multiple values e.g., $Items(John)="Hat;Lantern;Map"; ) provided that they’re grouped together. Have I got that right?

Putting that aside for a minute, it seems like I should create $Amount as a set or list data type (perhaps more of a list, since I’ll be referencing one amount per note). My question is: Will I be able to successfully import figures that contain dollar signs, commas, and decimals into the value field, e.g. $2,500.50 ?

I want to make sure that’ll work before I change one of the scripts I’m working with. Thanks!

Think of it this way EVERYTHING IS alphanumeric text, a string, a number, a boolean, a date, etc.

That attribute type tells tinderbox how do address or consider the text.

For Example:
Take two sets of text:

  1. See the cat run; don’t you think it is fast?
  2. Hat;Map;Lantern;Hat

Both these examples can be treated as a string, as a list, or a set.

As a string
When you tell Tinderbox that both these values are strings then Tinderbox will consider them as “one” set of characters.

As a List
If you tell Tinderbox they’re a list then Tinderbox will break the text at the semicolon when you run operations like a .each(x). In the first example the items of the list are 1) See the cat run, and 2) don’t you think it is fast?. For the second example there are four items that Tinderbox will see: 1) Hat, 2), Map, 3), Latern, 4) Hat.

As a Set
If you tell Tinderbox they’re a set then Tinderbox will break the text at the semicolon, remove duplicates, and sort them alphabetically. In the first example the items of the set are 1) don’t you think it is fast?, and 2) ) See the cat run, For the second example there are three items that Tinderbox will see: 1) Hat, 2), Latern, 3), Map. Tinderbox resources the items and removes duplciates.

No! Amount is a number, so put it in a number field; that is, unless you intend to import multiple amounts into a set attributes. For example,

The price of the fish is 1.99?

If this is the case then you’d have $Amount as a number and the value you’d want is 1.99. Don’t put the $ or thousands of operators. That is for visual output.

The price of the salmon was 1.99, tilapia 2.25, and trout 3.25. In this case, you might use a set: 1.99;2.25;3.25. But, what would be better is a dictionary: salmon;1.99;tilapia:2.25;trough:3.25.

Not sure what mean by referencing data for each note… that does not make sense to me.