Format a label element

How can I give a numeric format to a label element? That propery does not exist for labels

Thanks in advance

I suppose you want to format the value of a dataprovider?

Create a calculation, where you can format the value using utils.numberFormat() function.

It would be cool if we could apply formatting for labels like this:

%%unitprice|¤#.00%%

+1

+1 :)

+1

+1

Agree, but it would be nice if this is also possible when creating a label with tags.

%%…%%

and that you can format this also (using a designtime property, or somehow in the %%…%%)

Did formatting of labels make it into Servoy 6?

I recall speaking with Paul Bakker at Servoy World about this and was told it would be included in Servoy 6. I also saw the feature request in text form somewhere (forum, support, e-mail, etc), but I cannot locate it. In Servoy 6, I was expecting to see a ‘format’ property when selecting a label (similar to the field format property), but it’s not there.Perhaps, label formatting made it into Servoy 6 but is implemented differently from what I was expecting. Does anyone know about this?

Hi Kim,

I think you must have misinterpreted what I said, because formatting on labels has never bee on the roadmap for Servoy 6.0.

Label formatting is scheduled for the next version of Servoy though, based on feedback from yourself and others at ServoyWorld '11.

Paul

Hi, Paul.

Please let us know when it gets implemeneted.

I am using form variables as my dataprovider and setting them in the onrender event using something like…

_myFormVar = utils.numberFormat(foundset.myField, "$####,###,###,##0")

No workaround is ever as simple as you’d like it to be. Anyway, here is the code I ended up using in my project. I hope it is helpful to someone. This code eliminates the need for me to create calculations, but still allows me to use a button and show a hand icon and display formatted data. By the way, all of my form variables start with an underscore and are named somewhat like the table field (e.g. field: daytotal, formvar: _day).

function onRender(event)
{
    // TODO: Put format in button object if that property is added.
    // Using buttons to show data - format before showing.
    /** @type {JSRecord<db:/statistics/daymonthstats>}  */ 
    var record = event.getRecord();
    var element = event.getRenderable();
    var providerId = element.getDataProviderID();
    if (record.stattype && providerId && providerId.match(/^_/) && providerId !== "_statTypeLabel")
    {
        var format = (record.stattype.match(/dollar/i) ? "$" : "") + "####,###,###,##0";
        var name = providerId.substr(1).toLowerCase() + "total";
        var form = forms[controller.getName()];
        form[providerId] = utils.numberFormat(record[name], format);
    }
}