wrote:
wrote:
Hello Vonnelize,
the problem seems to be that the input mask you are using always interprets the last two digits of the stored value as the decimals, while the decimal-format of the value doesn't save trailing zeros (for reference: a stored value of 2.5 is shown as $0.25). This is similar to this problem https://www.outsystems.com/forums/discussion/35103/error-covnerting-data-type-decimal-to-decimal/ in that displaying a stored decimal value can be tricky.
The way I'd deal with this would be to not use the mask and not input the value as a number, but to use Text for input and output and convert between text and decimal data types. This would allow you to perform text-based checks in the OnAfterFetch-action, like
If( Index(DecimalToText(GetOrderById.List.Current.Order.CurrencyValue), ".", searchFromEnd: True) = 1, TextToDecimal(Concat(DecimalToText(GetOrderById.List.Current.Order.CurrencyValue),"0")), If(Index(DecimalToText(GetOrderById.List.Current.Order.CurrencyValue), ".", searchFromEnd: True) = -1, TextToDecimal(Concat(DecimalToText(GetOrderById.List.Current.Order.CurrencyValue),".00")), GetOrderById.List.Current.Order.CurrencyValue) )
This would add the trailing zeros based on how many decimal places were stored with it. To display the stored value in an expression you could also potentionaly use function "format/formatcurrency" (like the others I used to be found under the built-in functions).
Similary, if you don't want to convert between decimal and text, you could try to continue using the input mask and the function "Mod(n,m)" to determine if you have less than 2 decimal places in your stored value, and then (temporarily) mulitply by 10 or 100. You just need to remember to divide by the same number again if the value doesn't get changed, since you'll increase the stored number everytime someone displays it otherwise.
I am sure there are more elegant ways to solve this, although they might involve JavaScript. I hope this helps.
Best regards,
Michael
Hi Michael, thanks for the detailed response.
Your recommended solutions can work and I will try the second option. However I have loads of currency fields on the app that I need to display this way. Your solutions requires coding on every field instead of just using standard functionality so it becomes a big task to never be able to use the database and always use temporary text variables or calculations. It kind of defeats the idea of simple drag and drop of basic functionality ;-(
I am going to try your solution but I was really hoping that there is a better and easy way to handle masks in OutSystems.
I will let you know how it goes!
Hi Vonnelize,
I would actually recommend to use the first option if you have lots of fields. You should be able to create one or two custom client actions that contain the needed logic / conversions and you can just use those as your OnAfterFetch - action and one you can drag into every "save" action instead of manually coding every field etc. You can also just copy/paste an input field with the formatting set up the way you want it, only switching out the name of the field and the variable used. That should reduce the extra work considerably.
For replacing lots of the same variables F12 and Edit > Find & Replace (CTRL+R) save a lot of time and headaches.
Best regards;
Michael