Formatting Decimals To Currency

0
Hi, Is there a way to display in a data grid or a text box the decimal value as a currency ex. 10.0 → $ 10.0 We also want to be able to do this in a pdf table as well.  It seems that if there is not, then the easiest thing to do would be to never store an attribute as a decimal but rather as a string and then convert whenever you need to. Something using these functions could work https://docs.mendix.com/refguide/parse-and-format-decimal-function-calls Is there an easy way to display decimals or integers in a currency in a data grid or some how access a  function underneath? Thank you.  
asked
1 answers
0

There’s a couple of options here. For the datagrid, you can add currency as a property for the object, fill it by default (or not, if applicable) and add a column before the amount without a caption – then use text-left and text-right to align the columns to show their contents next to eachother.

An alternative is to add a (fixed) currency via styling (CSS) – add a certain column class to your currency column (ex. currencycolumn) and add the following styling to your stylesheets:

.currencycolumn > div:before {
	content: '$ ';
}

There’s also ways to combine these two tricks to show various currencies via styling but it’s quite complex.

For input fields it’s not as easy in Mendix – it’s possible by adding a container around the input field and a text element in the container. Then use position absolute & relative to position the text element at the front of the input field, and use text-indent to move the contents of the input field to clear the space used for the currency sign.

Hope this more-or-less paints a picture of how you could implement this.

answered