Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Expression Language: Get absolute value

I am trying to evaluate the expression where I need to have the absolute value of operator. My expression, after evaluation, looks like this:

((-4.0 - 3.0)/-4.0) * 100

I want absolute value of denominator to be substituted there.

I have tried using Math.abs() but it throws an exception while evaluating expression having abs() in it. Here are the expressions that I have tried (and failed):

((-4.0 - 3.0)/${#java.lang.Math.abs(-4.0)}) * 100
((-4.0 - 3.0)/#java.lang.Math.abs(-4.0)) * 100
((-4.0 - 3.0)/${java.lang.Math.abs(-4.0)}) * 100

Can anyone please let me know the correct syntax for this? Also, can we use bars to get absolute value (like |-4.0| or something)?

update

I have tried using bars (e.g. |-4.0| but even that hasn't worked.

like image 338
Darshan Mehta Avatar asked Dec 02 '25 01:12

Darshan Mehta


1 Answers

Use the T operator to invoke static methods...

T(java.lang.Math).abs(...)
like image 117
Gary Russell Avatar answered Dec 04 '25 18:12

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!