How to divide a user-entered Decimal value by 100 in Mendix?

0
Hello, I have a Decimal attribute (e.g., Rate) where the user enters a value through a text box.In a microflow, I want to take this user-entered Decimal value and divide it by 100 before saving it. I tried using a Change Object activity with the expression:   $MyEntity/Rate div 100 But this does not work as expected (the value becomes 0 because div performs integer division). What is the correct way to divide a Decimal attribute value by 100 in Mendix?For example, if the user enters 15, I would like to store 0.15.    
asked
3 answers
0

Try $MyEntity/Rate : 100.

 

Regards,

Ronald

 

answered
0

Div doesn't perform an integer division; it should return a Decimal even if you use integer values.

 

https://docs.mendix.com/refguide/arithmetic-expressions/#division

 

If you are seeing 0, I suspect something else is going on. Have you tried adding a breakpoint and examining the input and output values in the debugger straight after your division? 

answered
-1

Try this 

$MyEntity/Rate / 100

 

if you're using a variable 

$CalculatedRate = $MyEntity/Rate / 100 

 

Note:

Ensure that the Rate attribute is of type Decimal, Not Integer

 

you can aslo use FormatDecimal($MyEntity/Rate /100, '#0.00')).

 

for example: If the user enters 15, it will correctly store 0.15 in your decimal attribute.

answered