This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SUPPORT Q&A - Formatting numbers in a form

dhenning - Tuesday, December 9, 2008 11:27 AM:

I have tried my darnedest to find out how to get numbers to be formatted properly when displayed in a form - like $12,345.96 for currency or just the comma separator for thousands for a starter.  In the form I can't figure out where to do this....there doesn't seem to be a spot there, nor a spot in the Item Type definition - although there was a spot called 'Pattern' but the help says it is only for date.  How do I get 112345687.89 to Display as $112,345,687.89?

RobMcAveney - Tuesday, December 9, 2008 1:14 PM:

What version are you running?  There have been some changes to property formatting in the past couple releases.

Rob



dhenning - Tuesday, December 9, 2008 1:47 PM:

Sorry...we are at 8.1.0

RobMcAveney - Tuesday, December 9, 2008 2:03 PM:

In 8.1 you're a little more limited than you would be in 9.0, which has more number formatting options.  A couple more questions before I can give you the best answer... you mentioned you wanted the formatting on a Form.  Do you also need it to be on a grid?  Do you need to be able to search on the field and/or update it on the form?  There will be some minor scripting involved to get it the way you want it -- are you comfortable with that?



dhenning - Tuesday, December 9, 2008 3:44 PM:

Rob:

Well, one the form - updating the number is needed and would be nice, but on the grid as well would be great! Right now there is no need for searching on these fields.   and yes, some scripting I can handle.



RobMcAveney - Tuesday, December 9, 2008 8:25 PM:

I think the most flexible solution would be to create a federated property to contain the formatted value and expose as needed on grids and forms.  You would then use Server Events to sync the existing property with the federated property.  The existing property would be hidden on grids and forms, but would still be in the background and contain the same values.

Code like the following would be used as a C# server method and attached to your ItemType OnBeforeGet, OnBeforeAdd and OnBeforeUpdate.  This code strips the $ and , values out of the federated property value and sets the decimal property.

// Get the value of the federated property
string fedprop = this.getProperty("fedprop","");
// If the federated property has a value, strip out the $ and , characters and set the decimal property
if (fedprop.Length > 0) this.setProperty("decprop",fedprop.Replace("$","").Replace(",",""));
// If the federated property contains a wildcard, set the like condition on the decimal property
if (fedprop.Contains("*")) this.setPropertyAttribute("decprop","condition","like");
// Make sure the select list contains the decimal property
string sel = this.getAttribute("select","");
if (sel.Length > 1) this.setAttribute("select",sel+",decprop");
return this;

You will also need an OnAfterGet method to set the federated property to the formatted value of the decimal property.  The following C# code loops through the results and sets the value for each federated property.

// Loop through the items in the response
for (int i=0; i<this.getItemCount(); i++) {
    // Get the value of the decimal property
    string decprop = this.getItemByIndex(i).getProperty("decprop","");
    // If the decimal property has a value, format it as currency and set the federated property
    if (decprop.Length > 0) {
        decimal fedprop = Convert.ToDecimal(decprop);
        this.getItemByIndex(i).setProperty("fedprop",fedprop.ToString("C"));
    }
}    
return this;

This probably looks way more complicated than it is, but like I said it is easier in later versions.  Let me know if you have any questions.

Rob