Categories > TinyButStrong general >

onformat and php number_format()

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Trent
Date: 2007-01-17
Time: 19:43

onformat and php number_format()

I'm passing a value to my template that I'd like formatted in the following manner.

123456789  will display 123,456,789

I'm using php's built in number_format() function to display my data.

[user.total;onformat='number_format']

When I run the page that uses this piece of code, I get an error saying that the connection to my server is reset.  If I run it without the onformat bit, it runs fine.  Anyone have a solution for this?
By: sheepy
Date: 2007-01-18
Time: 02:26

Re: onformat and php number_format()

I don't know why it restarts (are you using latest PHP - 4.4.4 / 5.2?), but you can format string with tbs's own format parameter:

http://tinybutstrong.com/manual.php#html_field_prm_frm
By: Trent
Date: 2007-01-18
Time: 07:14

Re: onformat and php number_format()

Ther server restart is definitely a strange issue.

As for your advice sheepy, here's what I have now.

[user.total;frm='0,000']

This works, partially at least.

123456789 is displayed as 123456,789 when I apply the above tag.  Do I have to add the exact number of separations I want it to display like this maybe?
[user.total;frm='0,000,000,000,000']

When I do that, I get a lot of leading zeros and commas in front of my actual number to adjust to the format entered in the tag.

Unless there's another method of formatting it via TBS, I'll just format it via my php scripts and then pass it into the template.  It would just be much simpler to pass it to the template and then format through the template as I need to do a couple of calculations on this number that require that it isn't formatted with a thousands separator.
By: Skrol29
Date: 2007-01-19
Time: 01:15

Re: onformat and php number_format()

Hi,

This is normal.
The TBS numeric format assumes that the first symbol is for the decimal
separator.

If you want your value 123456789 to be displayed 123,456,789, the format is '0,000.'
the dot does matter.
By: Trent
Date: 2007-01-19
Time: 04:41

Re: onformat and php number_format()

Still acting strange.  It's displaying my number as 123456,789.

[user.total;frm='0,000.']
By: Trent
Date: 2007-01-19
Time: 04:43

Re: onformat and php number_format()

Nevermind, I left of the ".".  Now everything displays as it's supposed to.