Integer to float

0
Is there a way to store an integer value in a Float Type attribute? I tried parseFloat(toString($AdvanceRequest/AdvanceNew)), parseFloat(toString($AdvanceRequest/AdvanceNew)+'.00'), parseFloat(toString($AdvanceRequest/AdvanceNew)+'.00','#.##') and parseFloat(toString($AdvanceRequest/AdvanceNew)+'.00','#.00') but it still returns 50 in stead of 50.00 and the ChangeObject action gives 'An error has occured while handling the request'
asked
2 answers
0

Integer to float will always result in round values, hence there is no .00 added. To get a number to display with .00 (or .0 or .00000 or .N*0 or even .20 (instead of .2)) you will need to format the number. Mendix supplies the Currency attribute for this, but if you that's not sufficient for your needs you can solve it yourself by converting your number to a String with the desired formatting applied. In your example the Currency format should be enough, but otherwise you can use the formatFloat function instead (for more information see here).

And the error you mention: "the ChangeObject action gives 'An error has occured while handling the request'" seems to have little to do with the above, can you add the full stacktrace of the error in your original message so we can see in more detail what's going wrong?

answered
0

Create a variable float/currency and let it fill with the integer value. No need to parse. Parsing is for string to int or float not for int to float or float to int.

Regards,

Ronald

answered