decimal number formatting

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

decimal number formatting

Gaurav Sood
I have defined a generic output formatting for decimals in properties file like this:

 <property as="xs:string" name="oxf.xforms.format.output.decimal" value="if (. castable as xs:decimal) then format-number(xs:decimal(.),'###,###,###,##0.00;(###,###,###,##0.00)') else ."/>

This is working for outputs which have a ref attribute and the corresponding binding has a type of decimal eg
 <xf:output ref="."/>  -  works

 but for the computed fields where I am using the value attribute of xf:output to compute, this does not work. eg

 <xf:output value="sum(./values)/>   - does not work

I had read on w3c that value attribute will return string type, so I had tried adding another formatting in properties like this

 <property as="xs:string" name="oxf.xforms.format.output.string" value="if (. castable as xs:decimal) then format-number(xs:decimal(.),'###,###,###,##0.00;(###,###,###,##0.00)') else ."/>

but this has not worked either.

Any help will be appreciated

Thanks
Gaurav
Reply | Threaded
Open this post in threaded view
|

Re: decimal number formatting

Alessandro  Vernet
Administrator
Hi Gaurav,

Interesting question: it seems like the format is only used with a ref, not a value. An option would be for you to put the format in the xxf:format="…" attribute. Would that be an option? But if you have a number (pun intended!) of those fields, you might want just have a property that applies to all of them, instead of having to specify a xxf:format="…" on each one of them.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: decimal number formatting

Gaurav Sood
Hi Alex,

That's exactly what I would like to do. We have number of these fields and want a common formatting to apply to all regardless whether the output is using a ref or value. Is there any other way to do this?

Thanks
Gaurav
Reply | Threaded
Open this post in threaded view
|

Re: decimal number formatting

Alessandro  Vernet
Administrator
Hi Gaurav,

Again, what you're suggesting makes sense, so I've added an RFE for it:

https://github.com/orbeon/orbeon-forms/issues/2815

Now, I can't really think of a workaround, other than, obviously, having the value stored in the node of an instance. Wouldn't this be feasible in your case? I.e. maybe using an <xf:bind calculate="…"> instead of the <xf:output value="…"> and in the <xf:output> referencing that calculated node?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet